upload_profile.py 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  1. #!/usr/bin/python3
  2. import sys
  3. import os
  4. import sqlite3
  5. import json
  6. import math
  7. """
  8. Reads the API KEY, that must be passed as first command line argument.
  9. :returns: Recovered API KEY.
  10. :raises Exception: Th KEY couldn't be red.
  11. """
  12. def readKey():
  13. try:
  14. key = sys.argv[1]
  15. return key
  16. except Exception as e:
  17. print("Error parsing API KEY: " + str(e))
  18. raise
  19. """
  20. Reads the JSON data, that must be passed as second command line argument.
  21. :returns: Recovered data, in JSON format.
  22. :raises Exception: The data couldn't be red or converted to JSON.
  23. """
  24. def readData():
  25. try:
  26. #print(sys.argv[1])
  27. #data = json.loads(sys.argv[1])
  28. with open(sys.argv[2], 'r') as f:
  29. content = f.read()
  30. data = json.loads(content)
  31. return data
  32. except Exception as e:
  33. print("Error parsing data: " + str(e))
  34. raise
  35. """
  36. Verifies that the API key matches the player data and that it exists in th DB.
  37. :param db: Connection to the database.
  38. :returns: Connection to the database.
  39. :param data: Data in json format.
  40. :param key: API KEY.
  41. :returns: True if key and player match, False otherwise.
  42. :raises IntegrityError: The queryes couldn't bre executed.
  43. """
  44. def verifyKey(db, data, key):
  45. print('Verifying KEY...')
  46. status = False
  47. try:
  48. uid = data["wizard_info"]["wizard_id"]
  49. cursor = db.cursor()
  50. cursor.execute('SELECT count(uid) AS c FROM player WHERE uid = ? AND api_key = ?;', (uid, key))
  51. if cursor.fetchone()[0] == 1:
  52. status = True
  53. cursor.close()
  54. except sqlite3.IntegrityError as e:
  55. print("Error executing statement: " + str(e))
  56. raise
  57. return status
  58. """
  59. Opens the database file and cleans the user tables.
  60. It also disables referencial integrity.
  61. :param name: The path to the sqlite database.
  62. :returns: Connection to the database.
  63. :raises IntegrityError: The queryes couldn't bre executed.
  64. :raises IOError: The sqlite file couldn't be created.
  65. """
  66. def openDatabase():
  67. kdb = os.path.dirname(os.path.realpath(sys.argv[0])) + '/../../../sw.sqlite'
  68. udb = os.path.dirname(os.path.realpath(sys.argv[0])) + '/../../../../data/sw.sqlite'
  69. print('Configuring database...')
  70. try:
  71. db = sqlite3.connect(kdb)
  72. cursor = db.cursor()
  73. cursor.execute("attach '" + udb + "' as data;")
  74. cursor.close()
  75. return db
  76. except sqlite3.IntegrityError as e:
  77. print("Error executing statement: " + str(e))
  78. raise
  79. except IOError as e:
  80. print("I/O Error creating database " + name + ": " + str(e))
  81. raise
  82. """
  83. Clears the user tables.
  84. It also disables referencial integrity.
  85. :param db: Sqlite database connection.
  86. :param data: Data in json format.
  87. :raises IntegrityError: The queryes couldn't bre executed.
  88. """
  89. def clearData(db, data):
  90. print('Clearing previous data...')
  91. try:
  92. uid = str(data["wizard_info"]["wizard_id"])
  93. cursor = db.cursor()
  94. cursor.execute('PRAGMA foreign_keys = OFF;')
  95. cursor.execute('DELETE FROM scenario WHERE uid = ?', [uid])
  96. cursor.execute('DELETE FROM defense WHERE uid = ?', [uid])
  97. cursor.execute('DELETE FROM unit_skill WHERE unit IN (SELECT id FROM unit WHERE uid = ?)', [uid])
  98. cursor.execute('DELETE FROM unit WHERE uid = ?', [uid])
  99. cursor.execute('DELETE FROM rune WHERE uid = ?', [uid])
  100. cursor.execute('DELETE FROM building WHERE uid = ?', [uid])
  101. cursor.execute('DELETE FROM decoration WHERE uid = ?', [uid])
  102. cursor.execute('DELETE FROM inventory WHERE uid = ?', [uid])
  103. cursor.execute('DELETE FROM summon_special') # For every player, will be reloaded.
  104. cursor.execute('DELETE FROM rune_craft WHERE uid = ?', [uid])
  105. # 'guild' and 'guild_member' tables are cleared before inserting.
  106. db.commit()
  107. cursor.close();
  108. except sqlite3.IntegrityError as e:
  109. print("Error executing statement: " + str(e))
  110. raise
  111. return
  112. """
  113. Closes the database.
  114. Before doing so, it also disables referencial integrity.
  115. :param db: Connection to the database.
  116. :returns: Connection to the database.
  117. :raises IntegrityError: The queryes couldn't bre executed.
  118. """
  119. def closeDatabase(name):
  120. print('Closing database connection...')
  121. try:
  122. cursor = db.cursor()
  123. cursor.execute('PRAGMA foreign_keys = ON;')
  124. cursor.close()
  125. db.commit()
  126. db.close()
  127. except sqlite3.IntegrityError as e:
  128. print("Error executing statement: " + str(e))
  129. raise
  130. """
  131. Inserts a row into the database.
  132. :param db: Connection to the database.
  133. :param table: Name of the table to insert into.
  134. :param values: List of values to insert.
  135. :raises IntegrityError: The insert query was unsuccesfull.
  136. """
  137. def insert(db, table, values):
  138. cursor = db.cursor()
  139. db.execute('PRAGMA foreign_keys = OFF;')
  140. placeholders = ''
  141. for x in range(0, len(values)):
  142. placeholders = placeholders + '?, '
  143. placeholders = placeholders[:len(placeholders) - 2]
  144. query = 'INSERT INTO ' + table + ' VALUES (' + placeholders + ')'
  145. try:
  146. cursor.execute(query, values)
  147. except sqlite3.IntegrityError as e:
  148. print('Error Inserting into ' + table + ' with values (' + str(values) + '): ' + str(e))
  149. raise
  150. cursor.close;
  151. """
  152. Parses player (table player).
  153. :param db: Sqlite database connection.
  154. :param data: Data in json format.
  155. """
  156. def parsePlayer(db, data):
  157. print("Parsing player...")
  158. cursor = db.cursor()
  159. uid = data["wizard_info"]["wizard_id"]
  160. name = data["wizard_info"]["wizard_name"]
  161. # TODO: Generate data
  162. mail = data["wizard_info"]["wizard_name"]
  163. password = data["wizard_info"]["wizard_name"]
  164. api_key = data["wizard_info"]["wizard_name"]
  165. mana = data["wizard_info"]["wizard_mana"]
  166. crystal = data["wizard_info"]["wizard_crystal"]
  167. country = data["wizard_info"]["wizard_last_country"]
  168. lang = data["wizard_info"]["wizard_last_lang"]
  169. level = data["wizard_info"]["wizard_level"]
  170. experience = data["wizard_info"]["experience"]
  171. energy = data["wizard_info"]["wizard_energy"]
  172. energy_max = data["wizard_info"]["energy_max"]
  173. energy_per_min = data["wizard_info"]["energy_per_min"]
  174. arena_energy = data["wizard_info"]["arena_energy"]
  175. arena_energy_max = data["wizard_info"]["arena_energy_max"]
  176. rep = data["wizard_info"]["rep_unit_id"]
  177. social_point = data["wizard_info"]["social_point_current"]
  178. honor_point = data["wizard_info"]["honor_point"]
  179. guild_point = data["wizard_info"]["guild_point"]
  180. darkportal_energy = data["wizard_info"]["darkportal_energy"]
  181. darkportal_energy_max = data["wizard_info"]["darkportal_energy_max"]
  182. dimension_energy = data["dimension_hole_info"]["energy"]
  183. dimension_energy_max = data["dimension_hole_info"]["energy_max"]
  184. costume_point = data["wizard_info"]["costume_point"]
  185. costume_point_max = data["wizard_info"]["costume_point_max"]
  186. honor_medal = data["wizard_info"]["honor_medal"]
  187. honor_mark = data["wizard_info"]["honor_mark"]
  188. event_coin = data["wizard_info"]["event_coin"]
  189. storage_slots = data["unit_depository_slots"]["number"]
  190. island_upgrade = 0
  191. for island in data["island_info"]:
  192. if island["id"] <= 7 and island["open"] == 1:
  193. island_upgrade = island["id"]
  194. query = '''
  195. UPDATE player
  196. SET mana = ?,
  197. crystal = ?,
  198. country = ?,
  199. lang = ?,
  200. level = ?,
  201. experience = ?,
  202. energy = ?,
  203. energy_max = ?,
  204. energy_per_min = ?,
  205. arena_energy = ?,
  206. arena_energy_max = ?,
  207. rep = ?,
  208. social_point = ?,
  209. honor_point = ?,
  210. guild_point = ?,
  211. darkportal_energy = ?,
  212. darkportal_energy_max = ?,
  213. dimension_energy = ?,
  214. dimension_energy_max = ?,
  215. costume_point = ?,
  216. costume_point_max = ?,
  217. honor_medal = ?,
  218. honor_medal = ?,
  219. event_coin = ?,
  220. storage_slots = ?,
  221. island = ?
  222. WHERE uid = ?;
  223. '''
  224. values = (
  225. mana, crystal, country,
  226. lang, level, experience,
  227. energy, energy_max, energy_per_min,
  228. arena_energy, arena_energy_max, rep,
  229. social_point, honor_point, guild_point,
  230. darkportal_energy, darkportal_energy_max, dimension_energy,
  231. dimension_energy_max, costume_point, costume_point_max,
  232. honor_medal, honor_medal, event_coin,
  233. storage_slots, island_upgrade, uid
  234. )
  235. try:
  236. cursor.execute(query, values)
  237. db.commit()
  238. except sqlite3.IntegrityError as e:
  239. print('Error updating player table with: ' + str(query) + ' <== ' + str(values) + ' || Error message:' + str(e))
  240. raise
  241. """
  242. Parses scenarios (table scenario).
  243. :param db: Sqlite database connection.
  244. :param data: Data in json format.
  245. """
  246. def parseScenarios(db, data):
  247. print("Parsing scenarios...")
  248. uid = data["wizard_info"]["wizard_id"]
  249. for sce in data["scenario_list"]:
  250. region = sce["region_id"]
  251. difficulty = sce["difficulty"]
  252. cleared = sce["cleared"]
  253. max_cleared = 0
  254. for stage in sce["stage_list"]:
  255. if stage["cleared"] == 1:
  256. max_cleared = stage["stage_no"]
  257. insert(db, "scenario", (uid, region, difficulty, cleared, max_cleared))
  258. db.commit()
  259. """
  260. Parses arena defense units (table defense).
  261. :param db: Sqlite database connection.
  262. :param data: Data in json format.
  263. """
  264. def parseDefense(db, data):
  265. print("Parsing arena defense...")
  266. uid = data["wizard_info"]["wizard_id"]
  267. for defense in data["defense_unit_list"]:
  268. unit = defense["unit_id"]
  269. position = defense["pos_id"]
  270. insert(db, "defense", (uid, unit, position))
  271. db.commit()
  272. """
  273. Parses buildings (table building).
  274. :param db: Sqlite database connection.
  275. :param data: Data in json format.
  276. """
  277. def parseBuildings(db, data):
  278. print("Parsing buildings...")
  279. uid = data["wizard_info"]["wizard_id"]
  280. for bui in data["building_list"]:
  281. id = bui["building_id"]
  282. building = bui["building_master_id"]
  283. gain = bui["gain_per_hour"]
  284. insert(db, "building", (uid, id, building, gain))
  285. db.commit()
  286. """
  287. Parses decoration buildings (table dcoration).
  288. :param db: Sqlite database connection.
  289. :param data: Data in json format.
  290. """
  291. def parseDecorations(db, data):
  292. print("Parsing decorations...")
  293. uid = data["wizard_info"]["wizard_id"]
  294. for bui in data["deco_list"]:
  295. id = bui["deco_id"]
  296. building = bui["master_id"]
  297. level = bui["level"]
  298. insert(db, "decoration", (uid, id, building, level))
  299. db.commit()
  300. """
  301. Parses unit data (tables unit, unit_skill).
  302. :param db: Sqlite database connection.
  303. :param data: Data in json format.
  304. """
  305. def parseUnits(db, data):
  306. print("Parsing monsters...")
  307. uid = data["wizard_info"]["wizard_id"]
  308. lock_list = data["unit_lock_list"]
  309. for mon in data["unit_list"]:
  310. id = mon["unit_id"]
  311. building = mon["building_id"]
  312. monster = mon["unit_master_id"]
  313. level = mon["unit_level"]
  314. stars = mon["class"]
  315. hp = mon["con"] * 15 # Always x15
  316. attack = mon["atk"]
  317. defense = mon["def"]
  318. speed = mon["spd"]
  319. crit_rate = mon["critical_rate"]
  320. crit_damage = mon["critical_damage"]
  321. resistance = mon["resist"]
  322. accuracy = mon["accuracy"]
  323. experience = mon["experience"]
  324. exp_gained = mon["exp_gained"]
  325. exp_gain_rate = mon["exp_gain_rate"]
  326. costume = mon["costume_master_id"]
  327. attribute = -1; # TODO: Attribute?
  328. source = mon["source"]
  329. create_time = mon["create_time"]
  330. homunculus = mon["homunculus"]
  331. homunculus_name = mon["homunculus_name"]
  332. lock = 0
  333. if id in lock_list:
  334. lock = 1
  335. insert(db, "unit", (uid, id, building, monster, level, stars, hp, attack, defense, speed, crit_rate, crit_damage, resistance, accuracy, experience, exp_gained, exp_gain_rate, costume, attribute, source, create_time, homunculus, homunculus_name, lock))
  336. for skill in mon["skills"]:
  337. skill_id = skill[0]
  338. skill_level = skill[1]
  339. insert(db, "unit_skill", (id, skill_id, skill_level))
  340. db.commit()
  341. """
  342. Parses inventory data (table inventory).
  343. :param db: Sqlite database connection.
  344. :param data: Data in json format.
  345. """
  346. def parseInventory(db, data):
  347. print("Parsing inventory...")
  348. uid = data["wizard_info"]["wizard_id"]
  349. for item in data["inventory_info"]:
  350. id = item["item_master_id"]
  351. type = item["item_master_type"]
  352. amount = item["item_quantity"]
  353. insert(db, "inventory", (uid, id, type, amount))
  354. # Fix rune craft item type.
  355. cursor = db.cursor()
  356. cursor.execute("UPDATE inventory SET type = 27 WHERE type = 29 AND id IN (2001, 4001, 4002, 4003, 9001, 9002, 9003, 8001);")
  357. cursor.close()
  358. """
  359. Parses summon stone list (table summon_special).
  360. :param db: Sqlite database connection.
  361. :param data: Data in json format.
  362. """
  363. def parseSummonSpecial(db, data):
  364. print("Parsing Summon stone monster list...")
  365. uid = data["wizard_info"]["wizard_id"]
  366. for unit in data["summon_special_info"]["this"]:
  367. insert(db, "summon_special", (0, unit))
  368. for unit in data["summon_special_info"]["next"]:
  369. insert(db, "summon_special", (1, unit))
  370. for unit in data["summon_special_info"]["third"]:
  371. insert(db, "summon_special", (2, unit))
  372. for unit in data["summon_special_info"]["fourth"]:
  373. insert(db, "summon_special", (3, unit))
  374. """
  375. Parses rune data (table rune).
  376. :param db: Sqlite database connection.
  377. :param data: Data in json format.
  378. """
  379. def parseRunes(db, data):
  380. print("Parsing runes...")
  381. STAT_HP = 1
  382. STAT_HP_PCT = 2
  383. STAT_ATK = 3
  384. STAT_ATK_PCT = 4
  385. STAT_DEF = 5
  386. STAT_DEF_PCT = 6
  387. STAT_SPD = 8
  388. STAT_CRIT_RATE_PCT = 9
  389. STAT_CRIT_DMG_PCT = 10
  390. STAT_RESIST_PCT = 11
  391. STAT_ACCURACY_PCT = 12
  392. MAIN_STAT_VALUES = {
  393. # [stat][stars][level]: value
  394. STAT_HP: {
  395. 1: [40, 85, 130, 175, 220, 265, 310, 355, 400, 445, 490, 535, 580, 625, 670, 804],
  396. 2: [70, 130, 190, 250, 310, 370, 430, 490, 550, 610, 670, 730, 790, 850, 910, 1092],
  397. 3: [100, 175, 250, 325, 400, 475, 550, 625, 700, 775, 850, 925, 1000, 1075, 1150, 1380],
  398. 4: [160, 250, 340, 430, 520, 610, 700, 790, 880, 970, 1060, 1150, 1240, 1330, 1420, 1704],
  399. 5: [270, 375, 480, 585, 690, 795, 900, 1005, 1110, 1215, 1320, 1425, 1530, 1635, 1740, 2088],
  400. 6: [360, 480, 600, 720, 840, 960, 1080, 1200, 1320, 1440, 1560, 1680, 1800, 1920, 2040, 2448],
  401. },
  402. STAT_HP_PCT: {
  403. 1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18],
  404. 2: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19],
  405. 3: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 38],
  406. 4: [5, 7, 9, 11, 13, 16, 18, 20, 22, 24, 27, 29, 31, 33, 36, 43],
  407. 5: [8, 10, 12, 15, 17, 20, 22, 24, 27, 29, 32, 34, 37, 40, 43, 51],
  408. 6: [11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 63],
  409. },
  410. STAT_ATK: {
  411. 1: [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 54],
  412. 2: [5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 73],
  413. 3: [7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57, 62, 67, 72, 77, 92],
  414. 4: [10, 16, 22, 28, 34, 40, 46, 52, 58, 64, 70, 76, 82, 88, 94, 112],
  415. 5: [15, 22, 29, 36, 43, 50, 57, 64, 71, 78, 85, 92, 99, 106, 113, 135],
  416. 6: [22, 30, 38, 46, 54, 62, 70, 78, 86, 94, 102, 110, 118, 126, 134, 160],
  417. },
  418. STAT_ATK_PCT: {
  419. 1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18],
  420. 2: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19],
  421. 3: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 38],
  422. 4: [5, 7, 9, 11, 13, 16, 18, 20, 22, 24, 27, 29, 31, 33, 36, 43],
  423. 5: [8, 10, 12, 15, 17, 20, 22, 24, 27, 29, 32, 34, 37, 40, 43, 51],
  424. 6: [11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 63],
  425. },
  426. STAT_DEF: {
  427. 1: [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 54],
  428. 2: [5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 73],
  429. 3: [7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57, 62, 67, 72, 77, 92],
  430. 4: [10, 16, 22, 28, 34, 40, 46, 52, 58, 64, 70, 76, 82, 88, 94, 112],
  431. 5: [15, 22, 29, 36, 43, 50, 57, 64, 71, 78, 85, 92, 99, 106, 113, 135],
  432. 6: [22, 30, 38, 46, 54, 62, 70, 78, 86, 94, 102, 110, 118, 126, 134, 160],
  433. },
  434. STAT_DEF_PCT: {
  435. 1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18],
  436. 2: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19],
  437. 3: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 38],
  438. 4: [5, 7, 9, 11, 13, 16, 18, 20, 22, 24, 27, 29, 31, 33, 36, 43],
  439. 5: [8, 10, 12, 15, 17, 20, 22, 24, 27, 29, 32, 34, 37, 40, 43, 51],
  440. 6: [11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 63],
  441. },
  442. STAT_SPD: {
  443. 1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18],
  444. 2: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19],
  445. 3: [3, 4, 5, 6, 8, 9, 10, 12, 13, 14, 16, 17, 18, 19, 21, 25],
  446. 4: [4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 30],
  447. 5: [5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 39],
  448. 6: [7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 42],
  449. },
  450. STAT_CRIT_RATE_PCT: {
  451. 1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18],
  452. 2: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19],
  453. 3: [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 37],
  454. 4: [4, 6, 8, 11, 13, 15, 17, 19, 22, 24, 26, 28, 30, 33, 35, 41],
  455. 5: [5, 7, 10, 12, 15, 17, 19, 22, 24, 27, 29, 31, 34, 36, 39, 47],
  456. 6: [7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 58],
  457. },
  458. STAT_CRIT_DMG_PCT: {
  459. 1: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19],
  460. 2: [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 37],
  461. 3: [4, 6, 9, 11, 13, 16, 18, 20, 22, 25, 27, 29, 32, 34, 36, 43],
  462. 4: [6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 57],
  463. 5: [8, 11, 15, 18, 21, 25, 28, 31, 34, 38, 41, 44, 48, 51, 54, 65],
  464. 6: [11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67, 80],
  465. },
  466. STAT_RESIST_PCT: {
  467. 1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18],
  468. 2: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19],
  469. 3: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 38],
  470. 4: [6, 8, 10, 13, 15, 17, 19, 21, 24, 26, 28, 30, 32, 35, 37, 44],
  471. 5: [9, 11, 14, 16, 19, 21, 23, 26, 28, 31, 33, 35, 38, 40, 43, 51],
  472. 6: [12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 64],
  473. },
  474. STAT_ACCURACY_PCT: {
  475. 1: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18],
  476. 2: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19],
  477. 3: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 38],
  478. 4: [6, 8, 10, 13, 15, 17, 19, 21, 24, 26, 28, 30, 32, 35, 37, 44],
  479. 5: [9, 11, 14, 16, 19, 21, 23, 26, 28, 31, 33, 35, 38, 40, 43, 51],
  480. 6: [12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 64],
  481. },
  482. }
  483. SUBSTAT_INCREMENTS = {
  484. # [stat][stars]: value
  485. # Max possible substat value can be found by multiplying by 5
  486. STAT_HP: {
  487. 1: 60,
  488. 2: 105,
  489. 3: 165,
  490. 4: 225,
  491. 5: 300,
  492. 6: 375,
  493. },
  494. STAT_HP_PCT: {
  495. 1: 2,
  496. 2: 3,
  497. 3: 5,
  498. 4: 6,
  499. 5: 7,
  500. 6: 8,
  501. },
  502. STAT_ATK: {
  503. 1: 4,
  504. 2: 5,
  505. 3: 8,
  506. 4: 10,
  507. 5: 15,
  508. 6: 20,
  509. },
  510. STAT_ATK_PCT: {
  511. 1: 2,
  512. 2: 3,
  513. 3: 5,
  514. 4: 6,
  515. 5: 7,
  516. 6: 8,
  517. },
  518. STAT_DEF: {
  519. 1: 4,
  520. 2: 5,
  521. 3: 8,
  522. 4: 10,
  523. 5: 15,
  524. 6: 20,
  525. },
  526. STAT_DEF_PCT: {
  527. 1: 2,
  528. 2: 3,
  529. 3: 5,
  530. 4: 6,
  531. 5: 7,
  532. 6: 8,
  533. },
  534. STAT_SPD: {
  535. 1: 1,
  536. 2: 2,
  537. 3: 3,
  538. 4: 4,
  539. 5: 5,
  540. 6: 6,
  541. },
  542. STAT_CRIT_RATE_PCT: {
  543. 1: 1,
  544. 2: 2,
  545. 3: 3,
  546. 4: 4,
  547. 5: 5,
  548. 6: 6,
  549. },
  550. STAT_CRIT_DMG_PCT: {
  551. 1: 2,
  552. 2: 3,
  553. 3: 4,
  554. 4: 5,
  555. 5: 6,
  556. 6: 7,
  557. },
  558. STAT_RESIST_PCT: {
  559. 1: 2,
  560. 2: 3,
  561. 3: 5,
  562. 4: 6,
  563. 5: 7,
  564. 6: 8,
  565. },
  566. STAT_ACCURACY_PCT: {
  567. 1: 2,
  568. 2: 3,
  569. 3: 5,
  570. 4: 6,
  571. 5: 7,
  572. 6: 8,
  573. },
  574. }
  575. uid = data["wizard_info"]["wizard_id"]
  576. # Unequipped runes
  577. for rune in data["runes"]:
  578. id = rune["rune_id"]
  579. assigned_to = rune["occupied_id"]
  580. if assigned_to == 0:
  581. assigned_to = None
  582. runeset = rune["set_id"]
  583. slot = rune["slot_no"]
  584. stars = rune["class"]
  585. ancient = 0
  586. level = rune["upgrade_curr"]
  587. original_quality = rune["extra"]
  588. value = rune["sell_value"]
  589. if stars > 10:
  590. ancient = 1
  591. stars = stars - 10
  592. original_quality = original_quality - 10
  593. if level >= 12:
  594. quality = 5
  595. elif level >= 9:
  596. quality = 4
  597. elif level >= 6:
  598. quality = 3
  599. elif level >= 3:
  600. quality = 2
  601. else:
  602. quality = 1
  603. if original_quality > quality:
  604. quality = original_quality
  605. efficiency = 0
  606. max_efficiency = 0
  607. main_stat = rune["pri_eff"][0]
  608. main_stat_value = rune["pri_eff"][1]
  609. if rune["prefix_eff"][0] > 0:
  610. innate_stat = rune["prefix_eff"][0]
  611. innate_stat_value = rune["prefix_eff"][1]
  612. else:
  613. innate_stat = None
  614. innate_stat_value = 0
  615. if len(rune["sec_eff"]) > 0:
  616. substat_1 = rune["sec_eff"][0][0]
  617. substat_1_value = rune["sec_eff"][0][1]
  618. substat_1_enchant = rune["sec_eff"][0][2]
  619. substat_1_grind = rune["sec_eff"][0][3]
  620. else:
  621. substat_1 = None
  622. substat_1_value = 0
  623. substat_1_enchant = 0
  624. substat_1_grind = 0
  625. if len(rune["sec_eff"]) > 1:
  626. substat_2 = rune["sec_eff"][1][0]
  627. substat_2_value = rune["sec_eff"][1][1]
  628. substat_2_enchant = rune["sec_eff"][1][2]
  629. substat_2_grind = rune["sec_eff"][1][3]
  630. else:
  631. substat_2 = None
  632. substat_2_value = 0
  633. substat_2_enchant = 0
  634. substat_2_grind = 0
  635. if len(rune["sec_eff"]) > 2:
  636. substat_3 = rune["sec_eff"][2][0]
  637. substat_3_value = rune["sec_eff"][2][1]
  638. substat_3_enchant = rune["sec_eff"][2][2]
  639. substat_3_grind = rune["sec_eff"][2][3]
  640. else:
  641. substat_3 = None
  642. substat_3_value = 0
  643. substat_3_enchant = 0
  644. substat_3_grind = 0
  645. if len(rune["sec_eff"]) > 3:
  646. substat_4 = rune["sec_eff"][3][0]
  647. substat_4_value = rune["sec_eff"][3][1]
  648. substat_4_enchant = rune["sec_eff"][3][2]
  649. substat_4_grind = rune["sec_eff"][3][3]
  650. else:
  651. substat_4 = None
  652. substat_4_value = 0
  653. substat_4_enchant = 0
  654. substat_4_grind = 0
  655. # Calculate efficiences
  656. efficiency = 0
  657. substats = []
  658. efficiency += float(MAIN_STAT_VALUES[main_stat][stars][15]) / float(MAIN_STAT_VALUES[main_stat][6][15])
  659. if innate_stat is not None:
  660. efficiency += innate_stat_value / float(SUBSTAT_INCREMENTS[innate_stat][6] * 5)
  661. if substat_1 is not None:
  662. substats.append(substat_1)
  663. efficiency += substat_1_value / float(SUBSTAT_INCREMENTS[substat_1][6] * 5)
  664. if substat_2 is not None:
  665. substats.append(substat_2)
  666. efficiency += substat_2_value / float(SUBSTAT_INCREMENTS[substat_2][6] * 5)
  667. if substat_3 is not None:
  668. substats.append(substat_3)
  669. efficiency += substat_3_value / float(SUBSTAT_INCREMENTS[substat_3][6] * 5)
  670. if substat_4 is not None:
  671. substats.append(substat_4)
  672. efficiency += substat_4_value / float(SUBSTAT_INCREMENTS[substat_4][6] * 5)
  673. efficiency = efficiency / 2.8 * 100
  674. max_efficiency = get_max_efficiency(substats, efficiency, level, stars, original_quality)
  675. if efficiency > 100:
  676. efficiency = 100;
  677. if max_efficiency > 100:
  678. max_efficiency = 100;
  679. insert(db, "rune", (uid, id, assigned_to, runeset, slot, stars, ancient, level, quality, original_quality, value, efficiency, max_efficiency, main_stat, main_stat_value, innate_stat, innate_stat_value, substat_1, substat_1_value, substat_1_enchant, substat_1_grind, substat_2, substat_2_value, substat_2_enchant, substat_2_grind, substat_3, substat_3_value, substat_3_enchant, substat_3_grind, substat_4, substat_4_value, substat_4_enchant, substat_4_grind))
  680. # Equipped runes
  681. for mon in data["unit_list"]:
  682. for rune in mon["runes"]:
  683. id = rune["rune_id"]
  684. assigned_to = rune["occupied_id"]
  685. if assigned_to == 0:
  686. assigned_to = None
  687. runeset = rune["set_id"]
  688. slot = rune["slot_no"]
  689. stars = rune["class"]
  690. ancient = 0
  691. level = rune["upgrade_curr"]
  692. original_quality = rune["extra"]
  693. value = rune["sell_value"]
  694. if stars > 10:
  695. ancient = 1
  696. stars = stars - 10
  697. original_quality = original_quality - 10
  698. if level >= 12:
  699. quality = 5
  700. elif level >= 9:
  701. quality = 5
  702. elif level >= 6:
  703. quality = 3
  704. elif level >= 3:
  705. quality = 2
  706. else:
  707. quality = 1
  708. if original_quality > quality:
  709. quality = original_quality
  710. efficiency = 0
  711. max_efficiency = 0
  712. main_stat = rune["pri_eff"][0]
  713. main_stat_value = rune["pri_eff"][1]
  714. if rune["prefix_eff"][0] > 0:
  715. innate_stat = rune["prefix_eff"][0]
  716. innate_stat_value = rune["prefix_eff"][1]
  717. else:
  718. innate_stat = None
  719. innate_stat_value = 0
  720. if len(rune["sec_eff"]) > 0:
  721. substat_1 = rune["sec_eff"][0][0]
  722. substat_1_value = rune["sec_eff"][0][1]
  723. substat_1_enchant = rune["sec_eff"][0][2]
  724. substat_1_grind = rune["sec_eff"][0][3]
  725. else:
  726. substat_1 = None
  727. substat_1_value = 0
  728. substat_1_enchant = 0
  729. substat_1_grind = 0
  730. if len(rune["sec_eff"]) > 1:
  731. substat_2 = rune["sec_eff"][1][0]
  732. substat_2_value = rune["sec_eff"][1][1]
  733. substat_2_enchant = rune["sec_eff"][1][2]
  734. substat_2_grind = rune["sec_eff"][1][3]
  735. else:
  736. substat_2 = None
  737. substat_2_value = 0
  738. substat_2_enchant = 0
  739. substat_2_grind = 0
  740. if len(rune["sec_eff"]) > 2:
  741. substat_3 = rune["sec_eff"][2][0]
  742. substat_3_value = rune["sec_eff"][2][1]
  743. substat_3_enchant = rune["sec_eff"][2][2]
  744. substat_3_grind = rune["sec_eff"][2][3]
  745. else:
  746. substat_3 = None
  747. substat_3_value = 0
  748. substat_3_enchant = 0
  749. substat_3_grind = 0
  750. if len(rune["sec_eff"]) > 3:
  751. substat_4 = rune["sec_eff"][3][0]
  752. substat_4_value = rune["sec_eff"][3][1]
  753. substat_4_enchant = rune["sec_eff"][3][2]
  754. substat_4_grind = rune["sec_eff"][3][3]
  755. else:
  756. substat_4 = None
  757. substat_4_value = 0
  758. substat_4_enchant = 0
  759. substat_4_grind = 0
  760. # Calculate efficiences
  761. efficiency = 0
  762. substats = []
  763. efficiency += float(MAIN_STAT_VALUES[main_stat][stars][15]) / float(MAIN_STAT_VALUES[main_stat][6][15])
  764. if innate_stat is not None:
  765. efficiency += innate_stat_value / float(SUBSTAT_INCREMENTS[innate_stat][6] * 5)
  766. if substat_1 is not None:
  767. substats.append(substat_1)
  768. efficiency += substat_1_value / float(SUBSTAT_INCREMENTS[substat_1][6] * 5)
  769. if substat_2 is not None:
  770. substats.append(substat_2)
  771. efficiency += substat_2_value / float(SUBSTAT_INCREMENTS[substat_2][6] * 5)
  772. if substat_3 is not None:
  773. substats.append(substat_3)
  774. efficiency += substat_3_value / float(SUBSTAT_INCREMENTS[substat_3][6] * 5)
  775. if substat_4 is not None:
  776. substats.append(substat_4)
  777. efficiency += substat_4_value / float(SUBSTAT_INCREMENTS[substat_4][6] * 5)
  778. efficiency = efficiency / 2.8 * 100
  779. max_efficiency = get_max_efficiency(substats, efficiency, level, stars, original_quality)
  780. if efficiency > 100:
  781. efficiency = 100;
  782. if max_efficiency > 100:
  783. max_efficiency = 100;
  784. insert(db, "rune", (uid, id, assigned_to, runeset, slot, stars, ancient, level, quality, original_quality, value, efficiency, max_efficiency, main_stat, main_stat_value, innate_stat, innate_stat_value, substat_1, substat_1_value, substat_1_enchant, substat_1_grind, substat_2, substat_2_value, substat_2_enchant, substat_2_grind, substat_3, substat_3_value, substat_3_enchant, substat_3_grind, substat_4, substat_4_value, substat_4_enchant, substat_4_grind))
  785. db.commit()
  786. """
  787. calculates the max efficiency of a rune.
  788. :param substats: Array of substat types, dont include empty ones.
  789. :param efficiency: Current rune efficiency.
  790. :param level: Current rune level.
  791. :param stars: Rune stars.
  792. :param quality: Rune original quality.
  793. :return Max. efficiency.
  794. """
  795. def get_max_efficiency(substats, efficiency, level, stars, quality):
  796. STAT_HP = 1
  797. STAT_HP_PCT = 2
  798. STAT_ATK = 3
  799. STAT_ATK_PCT = 4
  800. STAT_DEF = 5
  801. STAT_DEF_PCT = 6
  802. STAT_SPD = 8
  803. STAT_CRIT_RATE_PCT = 9
  804. STAT_CRIT_DMG_PCT = 10
  805. STAT_RESIST_PCT = 11
  806. STAT_ACCURACY_PCT = 12
  807. SUBSTAT_INCREMENTS = {
  808. # [stat][stars]: value
  809. STAT_HP: {
  810. 1: 60,
  811. 2: 105,
  812. 3: 165,
  813. 4: 225,
  814. 5: 300,
  815. 6: 375,
  816. },
  817. STAT_HP_PCT: {
  818. 1: 2,
  819. 2: 3,
  820. 3: 5,
  821. 4: 6,
  822. 5: 7,
  823. 6: 8,
  824. },
  825. STAT_ATK: {
  826. 1: 4,
  827. 2: 5,
  828. 3: 8,
  829. 4: 10,
  830. 5: 15,
  831. 6: 20,
  832. },
  833. STAT_ATK_PCT: {
  834. 1: 2,
  835. 2: 3,
  836. 3: 5,
  837. 4: 6,
  838. 5: 7,
  839. 6: 8,
  840. },
  841. STAT_DEF: {
  842. 1: 4,
  843. 2: 5,
  844. 3: 8,
  845. 4: 10,
  846. 5: 15,
  847. 6: 20,
  848. },
  849. STAT_DEF_PCT: {
  850. 1: 2,
  851. 2: 3,
  852. 3: 5,
  853. 4: 6,
  854. 5: 7,
  855. 6: 8,
  856. },
  857. STAT_SPD: {
  858. 1: 1,
  859. 2: 2,
  860. 3: 3,
  861. 4: 4,
  862. 5: 5,
  863. 6: 6,
  864. },
  865. STAT_CRIT_RATE_PCT: {
  866. 1: 1,
  867. 2: 2,
  868. 3: 3,
  869. 4: 4,
  870. 5: 5,
  871. 6: 6,
  872. },
  873. STAT_CRIT_DMG_PCT: {
  874. 1: 2,
  875. 2: 3,
  876. 3: 4,
  877. 4: 5,
  878. 5: 6,
  879. 6: 7,
  880. },
  881. STAT_RESIST_PCT: {
  882. 1: 2,
  883. 2: 3,
  884. 3: 5,
  885. 4: 6,
  886. 5: 7,
  887. 6: 8,
  888. },
  889. STAT_ACCURACY_PCT: {
  890. 1: 2,
  891. 2: 3,
  892. 3: 5,
  893. 4: 6,
  894. 5: 7,
  895. 6: 8,
  896. },
  897. }
  898. UPGRADE_VALUES = {
  899. rune_type: {
  900. stars: value/level_data[6]
  901. for stars, value in level_data.items()
  902. }
  903. for rune_type, level_data in SUBSTAT_INCREMENTS.items()
  904. }
  905. #substat_upgrades_remaining = (4 - math.floor((min(level, 12) / 3))) - (3 - quality)
  906. substat_upgrades_remaining = (4 - math.floor((min(level, 12) / 3))) - max((3 - quality), 0)
  907. new_stats = max(min(4 - len(substats), substat_upgrades_remaining), 0)
  908. old_stats = substat_upgrades_remaining - new_stats
  909. if old_stats > 0:
  910. # we can repeatedly upgrade the most value of the existing stats
  911. best_stat = max(
  912. 0, # ensure max() doesn't error if we only have one stat
  913. *[UPGRADE_VALUES[stat][stars] for stat in substats]
  914. )
  915. efficiency += best_stat * old_stats * 0.2 / 2.8 * 100
  916. if new_stats:
  917. # add the top N stats
  918. available_upgrades = sorted(
  919. [
  920. upgrade_value[stars]
  921. for stat, upgrade_value in UPGRADE_VALUES.items()
  922. if stat not in substats
  923. ],
  924. reverse=True
  925. )
  926. efficiency += sum(available_upgrades[:new_stats]) * 0.2 / 2.8 * 100
  927. return efficiency
  928. """
  929. Parses rune craft item data (table rune_craft).
  930. :param db: Sqlite database connection.
  931. :param data: Data in json format.
  932. """
  933. def parseRuneCraft(db, data):
  934. print("Parsing rune craft itmes...")
  935. uid = data["wizard_info"]["wizard_id"]
  936. for item in data["rune_craft_item_list"]:
  937. id = item["craft_item_id"]
  938. type = item["craft_type"]
  939. value = item["sell_value"]
  940. amount = str(item["amount"])
  941. """
  942. info : 5 or 6 digit number: RRSSQ
  943. RR: Rune
  944. SS: Stat
  945. Q: Quality
  946. """
  947. info = str(item["craft_type_id"])
  948. quality = int(info[-1:])
  949. stat = int(info[-4:-2])
  950. rune = int(info[:-4])
  951. insert(db, "rune_craft", (uid, id, type, quality, rune, stat, value, amount))
  952. """
  953. Parses guild data (tables guild, guild_member).
  954. :param db: Sqlite database connection.
  955. :param data: Data in json format.
  956. """
  957. def parseGuild(db, data):
  958. print("Parsing guild...")
  959. cursor = db.cursor()
  960. if (data["guild"]["guild_info"] == None):
  961. # No guild
  962. return
  963. if len(data["guild"]["guild_info"]) < 1:
  964. return
  965. guild = data["guild"]["guild_info"]
  966. id = guild["guild_id"]
  967. name = guild["name"]
  968. level = guild["level"]
  969. experience = guild["experience"]
  970. recruiting = guild["recruit_status"]
  971. members = guild["member_now"]
  972. leader = guild["master_wizard_id"]
  973. comment = guild["comment"]
  974. notice = guild["notice"]
  975. # Delete selected guild before inserting
  976. cursor.execute("DELETE FROM guild WHERE id = ?", [id])
  977. cursor.execute("DELETE FROM guild_member WHERE guild = ?", [id])
  978. db.commit()
  979. insert(db, "guild", (id, name, level, experience, recruiting, members, leader, comment, notice))
  980. # Single quates ahead, dirty fix
  981. for k, member in data["guild"]["guild_members"].items():
  982. m = json.loads(str(member).replace("'", '"'))
  983. id = m["wizard_id"]
  984. guild = member["guild_id"]
  985. grade = member["grade"]
  986. name = member["wizard_name"]
  987. level = member["wizard_level"]
  988. rating = member["rating_id"]
  989. arena_score = member["arena_score"]
  990. joined = member["join_timestamp"]
  991. last_login = member["last_login_timestamp"]
  992. in_war = 0 # Checked later
  993. has_defense = 0 # Checked later
  994. insert(db, "guild_member", (id, guild, grade, name, level, rating, arena_score, joined, last_login, in_war, has_defense))
  995. for war in data["guildwar_member_list"]:
  996. cursor.execute("UPDATE guild_member SET in_war = 1 WHERE guild = ? AND id = ?;", (war["guild_id"], war["wizard_id"]))
  997. for defense in data["guild_member_defense_list"]:
  998. if len(defense["unit_list"]) > 0:
  999. cursor.execute("UPDATE guild_member SET has_defense = 1 WHERE id = ?", [defense["wizard_id"]])
  1000. db.commit()
  1001. cursor.close()
  1002. """
  1003. Deletes teams whose members no longer exists.
  1004. :param db: Sqlite database connection.
  1005. """
  1006. def reconfigureTeams(db):
  1007. print("Fixing teams...")
  1008. uid = data["wizard_info"]["wizard_id"]
  1009. cursor = db.cursor()
  1010. cursor.execute("DELETE FROM team WHERE id IN (SELECT DISTINCT team FROM team_unit WHERE unit NOT IN (SELECT DISTINCT id FROM unit WHERE uid = ?)) AND uid = ?", (uid, uid))
  1011. cursor.execute("DELETE FROM team_unit WHERE unit NOT IN (SELECT DISTINCT id FROM unit) OR team NOT IN (SELECT DISTINCT id FROM team);")
  1012. db.commit()
  1013. cursor.close()
  1014. """
  1015. Begin script
  1016. """
  1017. try:
  1018. data = readData()
  1019. except Exception as e:
  1020. print("Error reading data: " + str(e))
  1021. sys.exit(400)
  1022. try:
  1023. key = readKey()
  1024. except Exception as e:
  1025. print("Error fetching API key: " + str(e))
  1026. sys.exit(400)
  1027. try:
  1028. db = openDatabase()
  1029. except Exception as e:
  1030. print("Error opening database: " + str(e))
  1031. sys.exit(500)
  1032. if verifyKey(db, data, key) == False:
  1033. print("Invalid API KEY...")
  1034. sys.exit(401)
  1035. else:
  1036. try:
  1037. clearData(db, data)
  1038. except Exception as e:
  1039. print("Error clearing data: " + str(e))
  1040. sys.exit(500)
  1041. try:
  1042. parsePlayer(db, data)
  1043. except Exception as e:
  1044. print("Error parsing player data: " + str(e))
  1045. sys.exit(400)
  1046. try:
  1047. parseScenarios(db, data)
  1048. except Exception as e:
  1049. print("Error parsing scenario data: " + str(e))
  1050. sys.exit(400)
  1051. try:
  1052. parseDefense(db, data)
  1053. except Exception as e:
  1054. print("Error parsing defense data: " + str(e))
  1055. sys.exit(400)
  1056. try:
  1057. parseBuildings(db, data)
  1058. except Exception as e:
  1059. print("Error parsing building data: " + str(e))
  1060. sys.exit(400)
  1061. try:
  1062. parseDecorations(db, data)
  1063. except Exception as e:
  1064. print("Error parsing decoration data: " + str(e))
  1065. sys.exit(400)
  1066. # TODO homunculus_skill_list
  1067. try:
  1068. parseUnits(db, data)
  1069. except Exception as e:
  1070. print("Error parsing unit data: " + str(e))
  1071. sys.exit(400)
  1072. try:
  1073. parseSummonSpecial(db, data)
  1074. except Exception as e:
  1075. print("Error parsing special summon data: " + str(e))
  1076. sys.exit(400)
  1077. try:
  1078. parseInventory(db, data)
  1079. except Exception as e:
  1080. print("Error parsing inventory data: " + str(e))
  1081. sys.exit(400)
  1082. try:
  1083. parseRunes(db, data)
  1084. except Exception as e:
  1085. print("Error parsing runes data: " + str(e))
  1086. sys.exit(400)
  1087. try:
  1088. parseRuneCraft(db, data)
  1089. except Exception as e:
  1090. print("Error parsing rune craft data: " + str(e))
  1091. sys.exit(400)
  1092. try:
  1093. parseGuild(db, data)
  1094. except Exception as e:
  1095. print("Error parsing guild data: " + str(e))
  1096. sys.exit(400)
  1097. try:
  1098. reconfigureTeams(db)
  1099. except Exception as e:
  1100. print("Error reconfiguring teams: " + str(e))
  1101. sys.exit(400)
  1102. try:
  1103. closeDatabase(db)
  1104. except Exception as e:
  1105. print("Error closing database: " + str(e))
  1106. # No error
  1107. sys.exit(200);