|
@@ -283,6 +283,18 @@ def insert(db, table, values):
|
|
|
raise
|
|
raise
|
|
|
cursor.close;
|
|
cursor.close;
|
|
|
|
|
|
|
|
|
|
+"""
|
|
|
|
|
+Dowwnloads a file.
|
|
|
|
|
+
|
|
|
|
|
+If OPT_DOWNLOAD is set to false, it will do nothing (but it will still return
|
|
|
|
|
+true).
|
|
|
|
|
+If OPT_DOWNLOAD_OVERWRITE it will only download the file if the target doesn't
|
|
|
|
|
+exist (but it will still return true if it does).
|
|
|
|
|
+
|
|
|
|
|
+:param url: File url.
|
|
|
|
|
+:param target: Full or relative path (whit filename to save the url).
|
|
|
|
|
+:returns: True on success, false on error.
|
|
|
|
|
+"""
|
|
|
def download(url, target):
|
|
def download(url, target):
|
|
|
if OPT_DOWNLOAD == False:
|
|
if OPT_DOWNLOAD == False:
|
|
|
return True
|
|
return True
|
|
@@ -294,6 +306,12 @@ def download(url, target):
|
|
|
except:
|
|
except:
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
|
|
+"""
|
|
|
|
|
+Parses building date (tables k_building, k_building_level).
|
|
|
|
|
+
|
|
|
|
|
+:param db: Sqlite database connection.
|
|
|
|
|
+:param url: Swarfarm APIv2, buildings.
|
|
|
|
|
+"""
|
|
|
def parseBuildings(db, url):
|
|
def parseBuildings(db, url):
|
|
|
print("Parsing buildings...")
|
|
print("Parsing buildings...")
|
|
|
http = urllib3.PoolManager()
|
|
http = urllib3.PoolManager()
|
|
@@ -322,6 +340,12 @@ def parseBuildings(db, url):
|
|
|
else:
|
|
else:
|
|
|
break
|
|
break
|
|
|
|
|
|
|
|
|
|
+"""
|
|
|
|
|
+Parses skill data (tables k_skill, k_skill_level, k_skill_effect).
|
|
|
|
|
+
|
|
|
|
|
+:param db: Sqlite database connection.
|
|
|
|
|
+:param url: Swarfarm APIv2, skills.
|
|
|
|
|
+"""
|
|
|
def parseSkills(db, url):
|
|
def parseSkills(db, url):
|
|
|
print("Parsing skills...")
|
|
print("Parsing skills...")
|
|
|
http = urllib3.PoolManager()
|
|
http = urllib3.PoolManager()
|
|
@@ -360,6 +384,12 @@ def parseSkills(db, url):
|
|
|
else:
|
|
else:
|
|
|
break
|
|
break
|
|
|
|
|
|
|
|
|
|
+"""
|
|
|
|
|
+Parses leader skills (table k_leader_skill).
|
|
|
|
|
+
|
|
|
|
|
+:param db: Sqlite database connection.
|
|
|
|
|
+:param url: Swarfarm APIv2, leader-skills.
|
|
|
|
|
+"""
|
|
|
def parseLeaderSkills(db, url):
|
|
def parseLeaderSkills(db, url):
|
|
|
print("Parsing leader skills...")
|
|
print("Parsing leader skills...")
|
|
|
http = urllib3.PoolManager()
|
|
http = urllib3.PoolManager()
|
|
@@ -382,6 +412,12 @@ def parseLeaderSkills(db, url):
|
|
|
else:
|
|
else:
|
|
|
break
|
|
break
|
|
|
|
|
|
|
|
|
|
+"""
|
|
|
|
|
+Parses skill effects (table k_effect).
|
|
|
|
|
+
|
|
|
|
|
+:param db: Sqlite database connection.
|
|
|
|
|
+:param url: Swarfarm APIv2, skill-efects.
|
|
|
|
|
+"""
|
|
|
def parseEffects(db, url):
|
|
def parseEffects(db, url):
|
|
|
print("Parsing skill effects...")
|
|
print("Parsing skill effects...")
|
|
|
http = urllib3.PoolManager()
|
|
http = urllib3.PoolManager()
|
|
@@ -403,6 +439,12 @@ def parseEffects(db, url):
|
|
|
else:
|
|
else:
|
|
|
break
|
|
break
|
|
|
|
|
|
|
|
|
|
+"""
|
|
|
|
|
+Parses monster sources (table k_source).
|
|
|
|
|
+
|
|
|
|
|
+:param db: Sqlite database connection.
|
|
|
|
|
+:param url: Swarfarm APIv2, craft-materials.
|
|
|
|
|
+"""
|
|
|
def parseSources(db, url):
|
|
def parseSources(db, url):
|
|
|
print("Parsing sources...")
|
|
print("Parsing sources...")
|
|
|
http = urllib3.PoolManager()
|
|
http = urllib3.PoolManager()
|
|
@@ -424,7 +466,13 @@ def parseSources(db, url):
|
|
|
else:
|
|
else:
|
|
|
break
|
|
break
|
|
|
|
|
|
|
|
|
|
+"""
|
|
|
|
|
+Parses monster data (tables k_monster, k_monster_essence, k_monster_source,
|
|
|
|
|
+k_monsster_skill).
|
|
|
|
|
|
|
|
|
|
+:param db: Sqlite database connection.
|
|
|
|
|
+:param url: Swarfarm APIv2, monsters.
|
|
|
|
|
+"""
|
|
|
def parseMonsters(db, url):
|
|
def parseMonsters(db, url):
|
|
|
print("Parsing monsters...")
|
|
print("Parsing monsters...")
|
|
|
http = urllib3.PoolManager()
|
|
http = urllib3.PoolManager()
|
|
@@ -532,9 +580,7 @@ def parseMonsters(db, url):
|
|
|
insert(db, "k_monster_source", (id, source["id"]))
|
|
insert(db, "k_monster_source", (id, source["id"]))
|
|
|
# TODO: craft_materials
|
|
# TODO: craft_materials
|
|
|
image = "https://swarfarm.com/static/herders/images/monsters/" + mon["image_filename"]
|
|
image = "https://swarfarm.com/static/herders/images/monsters/" + mon["image_filename"]
|
|
|
- #download(image, 'public/img/content/monster/' + str(id).zfill(4) + '.png')
|
|
|
|
|
- if id > 1215:
|
|
|
|
|
- download(image, 'public/img/content/monster/' + str(id).zfill(4) + '.png')
|
|
|
|
|
|
|
+ download(image, 'public/img/content/monster/' + str(id).zfill(4) + '.png')
|
|
|
|
|
|
|
|
# Next page
|
|
# Next page
|
|
|
db.commit()
|
|
db.commit()
|
|
@@ -544,6 +590,12 @@ def parseMonsters(db, url):
|
|
|
else:
|
|
else:
|
|
|
break
|
|
break
|
|
|
|
|
|
|
|
|
|
+"""
|
|
|
|
|
+Parses fusion data (table k_fusion).
|
|
|
|
|
+
|
|
|
|
|
+:param db: Sqlite database connection.
|
|
|
|
|
+:param url: Swarfarm APIv2, fusions.
|
|
|
|
|
+"""
|
|
|
def parseFusions(db, url):
|
|
def parseFusions(db, url):
|
|
|
print("Parsing fusions...")
|
|
print("Parsing fusions...")
|
|
|
http = urllib3.PoolManager()
|
|
http = urllib3.PoolManager()
|
|
@@ -566,6 +618,12 @@ def parseFusions(db, url):
|
|
|
else:
|
|
else:
|
|
|
break
|
|
break
|
|
|
|
|
|
|
|
|
|
+"""
|
|
|
|
|
+Parses crafting materials (table k_craft).
|
|
|
|
|
+
|
|
|
|
|
+:param db: Sqlite database connection.
|
|
|
|
|
+:param url: Swarfarm APIv2, craft-materials.
|
|
|
|
|
+"""
|
|
|
def parseCraft(db, url):
|
|
def parseCraft(db, url):
|
|
|
print("Parsing crafting materials...")
|
|
print("Parsing crafting materials...")
|
|
|
http = urllib3.PoolManager()
|
|
http = urllib3.PoolManager()
|
|
@@ -586,8 +644,25 @@ def parseCraft(db, url):
|
|
|
else:
|
|
else:
|
|
|
break
|
|
break
|
|
|
|
|
|
|
|
|
|
+"""
|
|
|
|
|
+Removes references to imperfect monsters.
|
|
|
|
|
|
|
|
|
|
+Imperfect monsters are only available in Japanese servers due to legal reasons,
|
|
|
|
|
+they are not needed for this app. They wont be deleted, but awakening chains
|
|
|
|
|
+wil be cut.
|
|
|
|
|
|
|
|
|
|
+:param db: Sqlite database connection.
|
|
|
|
|
+"""
|
|
|
|
|
+def removeImperfect():
|
|
|
|
|
+ SELECT id, element, name FROM k_monster WHERE awakens_from IN (SELECT id FROM k_monster WHERE name LIKE 'Imperfect %');
|
|
|
|
|
+ cursor = db.cursor()
|
|
|
|
|
+ cursor.execute('''
|
|
|
|
|
+ UPDATE k_monster
|
|
|
|
|
+ SET awakens_from = null
|
|
|
|
|
+ WHERE awakens_from IN (SELECT id FROM k_monster WHERE name LIKE 'Imperfect %')
|
|
|
|
|
+ ''');
|
|
|
|
|
+ db.commit()
|
|
|
|
|
+ cursor.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -603,3 +678,4 @@ parseSources(db, 'https://swarfarm.com/api/v2/monster-sources/')
|
|
|
parseMonsters(db, 'https://swarfarm.com/api/v2/monsters/')
|
|
parseMonsters(db, 'https://swarfarm.com/api/v2/monsters/')
|
|
|
parseFusions(db, 'https://swarfarm.com/api/v2/fusions/')
|
|
parseFusions(db, 'https://swarfarm.com/api/v2/fusions/')
|
|
|
parseCraft(db, 'https://swarfarm.com/api/v2/craft-materials/')
|
|
parseCraft(db, 'https://swarfarm.com/api/v2/craft-materials/')
|
|
|
|
|
+removeImperfect(db)
|