log-profile.py 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  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. #print(sys.argv[1])
  15. key = sys.argv[1]
  16. return key
  17. except Exception as e:
  18. print("Error parsing API KEY: " + str(e))
  19. raise
  20. """
  21. Reads the JSON data, that must be passed as second command line argument.
  22. :returns: Recovered data, in JSON format.
  23. :raises Exception: The data couldn't be red or converted to JSON.
  24. """
  25. def readData():
  26. try:
  27. #print(sys.argv[1])
  28. #data = json.loads(sys.argv[1])
  29. with open(sys.argv[2], 'r') as f:
  30. content = f.read()
  31. data = json.loads(content)
  32. return data
  33. except Exception as e:
  34. print("Error parsing data: " + str(e))
  35. raise
  36. """
  37. Verifies that the API key matches the player data and that it exists in th DB.
  38. :param db: Connection to the database.
  39. :returns: Connection to the database.
  40. :param data: Data in json format.
  41. :param key: API KEY.
  42. :returns: True if key and player match, False otherwise.
  43. :raises IntegrityError: The queryes couldn't bre executed.
  44. """
  45. def verifyKey(db, data, key):
  46. print('Verifying KEY...')
  47. status = False
  48. try:
  49. uid = data["wizard_info"]["wizard_id"]
  50. cursor = db.cursor()
  51. cursor.execute('SELECT count(uid) AS c FROM player WHERE uid = ? AND api_key = ?;', (uid, key))
  52. if cursor.fetchone()[0] == 1:
  53. status = True
  54. cursor.close()
  55. except sqlite3.IntegrityError as e:
  56. print("Error executing statement: " + str(e))
  57. raise
  58. return status
  59. """
  60. Opens the database file and cleans the user tables.
  61. It also disables referencial integrity.
  62. :param name: The path to the sqlite database.
  63. :returns: Connection to the database.
  64. :raises IntegrityError: The queryes couldn't bre executed.
  65. :raises IOError: The sqlite file couldn't be created.
  66. """
  67. def openDatabase():
  68. kdb = os.path.dirname(os.path.realpath(sys.argv[0])) + '/../sw.sqlite'
  69. udb = os.path.dirname(os.path.realpath(sys.argv[0])) + '/../../data/sw.sqlite'
  70. print('Configuring database...')
  71. try:
  72. db = sqlite3.connect(kdb)
  73. cursor = db.cursor()
  74. cursor.execute("attach '" + udb + "' as data;")
  75. cursor.close()
  76. return db
  77. except sqlite3.IntegrityError as e:
  78. print("Error executing statement: " + str(e))
  79. raise
  80. except IOError as e:
  81. print("I/O Error creating database " + name + ": " + str(e))
  82. raise
  83. """
  84. Clears the user tables.
  85. It also disables referencial integrity.
  86. :param db: Sqlite database connection.
  87. :param data: Data in json format.
  88. :raises IntegrityError: The queryes couldn't bre executed.
  89. """
  90. def clearData(db, data):
  91. print('Clearing previous data...')
  92. try:
  93. uid = str(data["wizard_info"]["wizard_id"])
  94. print('UID: ' + str(uid))
  95. cursor = db.cursor()
  96. cursor.execute('PRAGMA foreign_keys = OFF;')
  97. cursor.execute('DELETE FROM scenario WHERE uid = ?', [uid])
  98. cursor.execute('DELETE FROM defense WHERE uid = ?', [uid])
  99. cursor.execute('DELETE FROM unit_skill WHERE unit IN (SELECT id FROM unit WHERE uid = ?)', [uid])
  100. cursor.execute('DELETE FROM unit WHERE uid = ?', [uid])
  101. cursor.execute('DELETE FROM rune WHERE uid = ?', [uid])
  102. cursor.execute('DELETE FROM building WHERE uid = ?', [uid])
  103. cursor.execute('DELETE FROM decoration WHERE uid = ?', [uid])
  104. cursor.execute('DELETE FROM inventory WHERE uid = ?', [uid])
  105. cursor.execute('DELETE FROM summon_special') # For every player
  106. cursor.execute('DELETE FROM guild') # TODO: Dont delete all guilds
  107. cursor.execute('DELETE FROM guild_member') # TODO: Dont delete all guilds, fix table
  108. cursor.execute('DELETE FROM rune_craft WHERE uid = ?', [uid])
  109. db.commit()
  110. cursor.close();
  111. except sqlite3.IntegrityError as e:
  112. print("Error executing statement: " + str(e))
  113. raise
  114. return
  115. """
  116. Closes the database.
  117. Before doing so, it also disables referencial integrity.
  118. :param db: Connection to the database.
  119. :returns: Connection to the database.
  120. :raises IntegrityError: The queryes couldn't bre executed.
  121. """
  122. def closeDatabase(name):
  123. print('Closing database connection...')
  124. try:
  125. cursor = db.cursor()
  126. cursor.execute('PRAGMA foreign_keys = ON;')
  127. cursor.close()
  128. db.commit()
  129. db.close()
  130. except sqlite3.IntegrityError as e:
  131. print("Error executing statement: " + str(e))
  132. raise
  133. """
  134. Inserts a row into the database.
  135. :param db: Connection to the database.
  136. :param table: Name of the table to insert into.
  137. :param values: List of values to insert.
  138. :raises IntegrityError: The insert query was unsuccesfull.
  139. """
  140. def insert(db, table, values):
  141. cursor = db.cursor()
  142. db.execute('PRAGMA foreign_keys = OFF;')
  143. placeholders = ''
  144. for x in range(0, len(values)):
  145. placeholders = placeholders + '?, '
  146. placeholders = placeholders[:len(placeholders) - 2]
  147. query = 'INSERT INTO ' + table + ' VALUES (' + placeholders + ')'
  148. try:
  149. cursor.execute(query, values)
  150. except sqlite3.IntegrityError as e:
  151. print('Error Inserting into ' + table + ' with values (' + str(values) + '): ' + str(e))
  152. raise
  153. cursor.close;
  154. """
  155. Parses player (table player).
  156. :param db: Sqlite database connection.
  157. :param data: Data in json format.
  158. """
  159. def parsePlayer(db, data):
  160. print("Parsing player...")
  161. cursor = db.cursor()
  162. uid = data["wizard_info"]["wizard_id"]
  163. name = data["wizard_info"]["wizard_name"]
  164. # TODO: Generate data
  165. mail = data["wizard_info"]["wizard_name"]
  166. password = data["wizard_info"]["wizard_name"]
  167. api_key = data["wizard_info"]["wizard_name"]
  168. mana = data["wizard_info"]["wizard_mana"]
  169. crystal = data["wizard_info"]["wizard_crystal"]
  170. country = data["wizard_info"]["wizard_last_country"]
  171. lang = data["wizard_info"]["wizard_last_lang"]
  172. level = data["wizard_info"]["wizard_level"]
  173. experience = data["wizard_info"]["experience"]
  174. energy = data["wizard_info"]["wizard_energy"]
  175. energy_max = data["wizard_info"]["energy_max"]
  176. energy_per_min = data["wizard_info"]["energy_per_min"]
  177. arena_energy = data["wizard_info"]["arena_energy"]
  178. arena_energy_max = data["wizard_info"]["arena_energy_max"]
  179. rep = data["wizard_info"]["rep_unit_id"]
  180. social_point = data["wizard_info"]["social_point_current"]
  181. honor_point = data["wizard_info"]["honor_point"]
  182. guild_point = data["wizard_info"]["guild_point"]
  183. darkportal_energy = data["wizard_info"]["darkportal_energy"]
  184. darkportal_energy_max = data["wizard_info"]["darkportal_energy_max"]
  185. dimension_energy = data["dimension_hole_info"]["energy"]
  186. dimension_energy_max = data["dimension_hole_info"]["energy_max"]
  187. costume_point = data["wizard_info"]["costume_point"]
  188. costume_point_max = data["wizard_info"]["costume_point_max"]
  189. honor_medal = data["wizard_info"]["honor_medal"]
  190. honor_mark = data["wizard_info"]["honor_mark"]
  191. event_coin = data["wizard_info"]["event_coin"]
  192. storage_slots = data["unit_depository_slots"]["number"]
  193. island_upgrade = 0
  194. for island in data["island_info"]:
  195. if island["id"] <= 7 and island["open"] == 1:
  196. island_upgrade = island["id"]
  197. query = '''
  198. UPDATE player
  199. SET mana = ?,
  200. crystal = ?,
  201. country = ?,
  202. lang = ?,
  203. level = ?,
  204. experience = ?,
  205. energy = ?,
  206. energy_max = ?,
  207. energy_per_min = ?,
  208. arena_energy = ?,
  209. arena_energy_max = ?,
  210. rep = ?,
  211. social_point = ?,
  212. honor_point = ?,
  213. guild_point = ?,
  214. darkportal_energy = ?,
  215. darkportal_energy_max = ?,
  216. dimension_energy = ?,
  217. dimension_energy_max = ?,
  218. costume_point = ?,
  219. costume_point_max = ?,
  220. honor_medal = ?,
  221. honor_medal = ?,
  222. event_coin = ?,
  223. storage_slots = ?,
  224. island = ?
  225. WHERE uid = ?;
  226. '''
  227. values = (
  228. mana, crystal, country,
  229. lang, level, experience,
  230. energy, energy_max, energy_per_min,
  231. arena_energy, arena_energy_max, rep,
  232. social_point, honor_point, guild_point,
  233. darkportal_energy, darkportal_energy_max, dimension_energy,
  234. dimension_energy_max, costume_point, costume_point_max,
  235. honor_medal, honor_medal, event_coin,
  236. storage_slots, island_upgrade, uid
  237. )
  238. try:
  239. cursor.execute(query, values)
  240. db.commit()
  241. except sqlite3.IntegrityError as e:
  242. print('Error updating player table with: ' + str(query) + ' <== ' + str(values) + ' || Error message:' + str(e))
  243. raise
  244. """
  245. Parses scenarios (table scenario).
  246. :param db: Sqlite database connection.
  247. :param data: Data in json format.
  248. """
  249. def parseScenarios(db, data):
  250. print("Parsing scenarios...")
  251. uid = data["wizard_info"]["wizard_id"]
  252. for sce in data["scenario_list"]:
  253. region = sce["region_id"]
  254. difficulty = sce["difficulty"]
  255. cleared = sce["cleared"]
  256. max_cleared = 0
  257. for stage in sce["stage_list"]:
  258. if stage["cleared"] == 1:
  259. max_cleared = stage["stage_no"]
  260. insert(db, "scenario", (uid, region, difficulty, cleared, max_cleared))
  261. db.commit()
  262. """
  263. Parses arena defense units (table defense).
  264. :param db: Sqlite database connection.
  265. :param data: Data in json format.
  266. """
  267. def parseDefense(db, data):
  268. print("Parsing arena defense...")
  269. uid = data["wizard_info"]["wizard_id"]
  270. for defense in data["defense_unit_list"]:
  271. unit = defense["unit_id"]
  272. position = defense["pos_id"]
  273. insert(db, "defense", (uid, unit, position))
  274. db.commit()
  275. """
  276. Parses buildings (table building).
  277. :param db: Sqlite database connection.
  278. :param data: Data in json format.
  279. """
  280. def parseBuildings(db, data):
  281. print("Parsing buildings...")
  282. uid = data["wizard_info"]["wizard_id"]
  283. for bui in data["building_list"]:
  284. id = bui["building_id"]
  285. building = bui["building_master_id"]
  286. gain = bui["gain_per_hour"]
  287. insert(db, "building", (uid, id, building, gain))
  288. db.commit()
  289. """
  290. Parses decoration buildings (table dcoration).
  291. :param db: Sqlite database connection.
  292. :param data: Data in json format.
  293. """
  294. def parseDecorations(db, data):
  295. print("Parsing decorations...")
  296. uid = data["wizard_info"]["wizard_id"]
  297. for bui in data["deco_list"]:
  298. id = bui["deco_id"]
  299. building = bui["master_id"]
  300. level = bui["level"]
  301. insert(db, "decoration", (uid, id, building, level))
  302. db.commit()
  303. """
  304. Parses unit data (tables unit, unit_skill).
  305. :param db: Sqlite database connection.
  306. :param data: Data in json format.
  307. """
  308. def parseUnits(db, data):
  309. print("Parsing monsters...")
  310. uid = data["wizard_info"]["wizard_id"]
  311. lock_list = data["unit_lock_list"]
  312. for mon in data["unit_list"]:
  313. id = mon["unit_id"]
  314. building = mon["building_id"]
  315. monster = mon["unit_master_id"]
  316. level = mon["unit_level"]
  317. stars = mon["class"]
  318. hp = mon["con"] * 15 # Always x15
  319. attack = mon["atk"]
  320. defense = mon["def"]
  321. speed = mon["spd"]
  322. crit_rate = mon["critical_rate"]
  323. crit_damage = mon["critical_damage"]
  324. resistance = mon["resist"]
  325. accuracy = mon["accuracy"]
  326. experience = mon["experience"]
  327. exp_gained = mon["exp_gained"]
  328. exp_gain_rate = mon["exp_gain_rate"]
  329. costume = mon["costume_master_id"]
  330. attribute = mon["attribute"]
  331. source = mon["source"]
  332. create_time = mon["create_time"]
  333. homunculus = mon["homunculus"]
  334. homunculus_name = mon["homunculus_name"]
  335. lock = 0
  336. if id in lock_list:
  337. lock = 1
  338. 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))
  339. for skill in mon["skills"]:
  340. skill_id = skill[0]
  341. skill_level = skill[1]
  342. insert(db, "unit_skill", (id, skill_id, skill_level))
  343. db.commit()
  344. """
  345. Parses inventory data (table inventory).
  346. :param db: Sqlite database connection.
  347. :param data: Data in json format.
  348. """
  349. def parseInventory(db, data):
  350. print("Parsing inventory...")
  351. uid = data["wizard_info"]["wizard_id"]
  352. for item in data["inventory_info"]:
  353. id = item["item_master_id"]
  354. type = item["item_master_type"]
  355. # TODO: Master id?
  356. amount = item["item_quantity"]
  357. insert(db, "inventory", (uid, id, type, amount))
  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. # TODO: Calculate
  606. #efficiency = rune["efficiency"]
  607. #max_efficiency = rune["max_efficiency"]
  608. efficiency = 0
  609. max_efficiency = 0
  610. main_stat = rune["pri_eff"][0]
  611. main_stat_value = rune["pri_eff"][1]
  612. if rune["prefix_eff"][0] > 0:
  613. innate_stat = rune["prefix_eff"][0]
  614. innate_stat_value = rune["prefix_eff"][1]
  615. else:
  616. innate_stat = None
  617. innate_stat_value = 0
  618. if len(rune["sec_eff"]) > 0:
  619. substat_1 = rune["sec_eff"][0][0]
  620. substat_1_value = rune["sec_eff"][0][1]
  621. substat_1_enchant = rune["sec_eff"][0][2]
  622. substat_1_grind = rune["sec_eff"][0][3]
  623. else:
  624. substat_1 = None
  625. substat_1_value = 0
  626. substat_1_enchant = 0
  627. substat_1_grind = 0
  628. if len(rune["sec_eff"]) > 1:
  629. substat_2 = rune["sec_eff"][1][0]
  630. substat_2_value = rune["sec_eff"][1][1]
  631. substat_2_enchant = rune["sec_eff"][1][2]
  632. substat_2_grind = rune["sec_eff"][1][3]
  633. else:
  634. substat_2 = None
  635. substat_2_value = 0
  636. substat_2_enchant = 0
  637. substat_2_grind = 0
  638. if len(rune["sec_eff"]) > 2:
  639. substat_3 = rune["sec_eff"][2][0]
  640. substat_3_value = rune["sec_eff"][2][1]
  641. substat_3_enchant = rune["sec_eff"][2][2]
  642. substat_3_grind = rune["sec_eff"][2][3]
  643. else:
  644. substat_3 = None
  645. substat_3_value = 0
  646. substat_3_enchant = 0
  647. substat_3_grind = 0
  648. if len(rune["sec_eff"]) > 3:
  649. substat_4 = rune["sec_eff"][3][0]
  650. substat_4_value = rune["sec_eff"][3][1]
  651. substat_4_enchant = rune["sec_eff"][3][2]
  652. substat_4_grind = rune["sec_eff"][3][3]
  653. else:
  654. substat_4 = None
  655. substat_4_value = 0
  656. substat_4_enchant = 0
  657. substat_4_grind = 0
  658. # Calculate efficiences
  659. efficiency = 0
  660. substats = []
  661. efficiency += float(MAIN_STAT_VALUES[main_stat][stars][15]) / float(MAIN_STAT_VALUES[main_stat][6][15])
  662. if innate_stat is not None:
  663. efficiency += innate_stat_value / float(SUBSTAT_INCREMENTS[innate_stat][6] * 5)
  664. if substat_1 is not None:
  665. substats.append(substat_1)
  666. efficiency += substat_1_value / float(SUBSTAT_INCREMENTS[substat_1][6] * 5)
  667. if substat_2 is not None:
  668. substats.append(substat_2)
  669. efficiency += substat_2_value / float(SUBSTAT_INCREMENTS[substat_2][6] * 5)
  670. if substat_3 is not None:
  671. substats.append(substat_3)
  672. efficiency += substat_3_value / float(SUBSTAT_INCREMENTS[substat_3][6] * 5)
  673. if substat_4 is not None:
  674. substats.append(substat_4)
  675. efficiency += substat_4_value / float(SUBSTAT_INCREMENTS[substat_4][6] * 5)
  676. efficiency = efficiency / 2.8 * 100
  677. max_efficiency = get_max_efficiency(substats, efficiency, level, stars, original_quality)
  678. if efficiency > 100:
  679. efficiency = 100;
  680. if max_efficiency > 100:
  681. max_efficiency = 100;
  682. 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))
  683. # Equipped runes
  684. for mon in data["unit_list"]:
  685. for rune in mon["runes"]:
  686. id = rune["rune_id"]
  687. assigned_to = rune["occupied_id"]
  688. if assigned_to == 0:
  689. assigned_to = None
  690. runeset = rune["set_id"]
  691. slot = rune["slot_no"]
  692. stars = rune["class"]
  693. ancient = 0
  694. level = rune["upgrade_curr"]
  695. original_quality = rune["extra"]
  696. value = rune["sell_value"]
  697. if stars > 10:
  698. ancient = 1
  699. stars = stars - 10
  700. original_quality = original_quality - 10
  701. if level >= 12:
  702. quality = 4
  703. elif level >= 9:
  704. quality = 3
  705. elif level >= 6:
  706. quality = 2
  707. elif level >= 3:
  708. quality = 1
  709. else:
  710. quality = 0
  711. if original_quality > quality:
  712. quality = original_quality
  713. # TODO: Calculate
  714. #efficiency = rune["efficiency"]
  715. #max_efficiency = rune["max_efficiency"]
  716. efficiency = 0
  717. max_efficiency = 0
  718. main_stat = rune["pri_eff"][0]
  719. main_stat_value = rune["pri_eff"][1]
  720. if rune["prefix_eff"][0] > 0:
  721. innate_stat = rune["prefix_eff"][0]
  722. innate_stat_value = rune["prefix_eff"][1]
  723. else:
  724. innate_stat = None
  725. innate_stat_value = 0
  726. if len(rune["sec_eff"]) > 0:
  727. substat_1 = rune["sec_eff"][0][0]
  728. substat_1_value = rune["sec_eff"][0][1]
  729. substat_1_enchant = rune["sec_eff"][0][2]
  730. substat_1_grind = rune["sec_eff"][0][3]
  731. else:
  732. substat_1 = None
  733. substat_1_value = 0
  734. substat_1_enchant = 0
  735. substat_1_grind = 0
  736. if len(rune["sec_eff"]) > 1:
  737. substat_2 = rune["sec_eff"][1][0]
  738. substat_2_value = rune["sec_eff"][1][1]
  739. substat_2_enchant = rune["sec_eff"][1][2]
  740. substat_2_grind = rune["sec_eff"][1][3]
  741. else:
  742. substat_2 = None
  743. substat_2_value = 0
  744. substat_2_enchant = 0
  745. substat_2_grind = 0
  746. if len(rune["sec_eff"]) > 2:
  747. substat_3 = rune["sec_eff"][2][0]
  748. substat_3_value = rune["sec_eff"][2][1]
  749. substat_3_enchant = rune["sec_eff"][2][2]
  750. substat_3_grind = rune["sec_eff"][2][3]
  751. else:
  752. substat_3 = None
  753. substat_3_value = 0
  754. substat_3_enchant = 0
  755. substat_3_grind = 0
  756. if len(rune["sec_eff"]) > 3:
  757. substat_4 = rune["sec_eff"][3][0]
  758. substat_4_value = rune["sec_eff"][3][1]
  759. substat_4_enchant = rune["sec_eff"][3][2]
  760. substat_4_grind = rune["sec_eff"][3][3]
  761. else:
  762. substat_4 = None
  763. substat_4_value = 0
  764. substat_4_enchant = 0
  765. substat_4_grind = 0
  766. # Calculate efficiences
  767. efficiency = 0
  768. substats = []
  769. efficiency += float(MAIN_STAT_VALUES[main_stat][stars][15]) / float(MAIN_STAT_VALUES[main_stat][6][15])
  770. if innate_stat is not None:
  771. efficiency += innate_stat_value / float(SUBSTAT_INCREMENTS[innate_stat][6] * 5)
  772. if substat_1 is not None:
  773. substats.append(substat_1)
  774. efficiency += substat_1_value / float(SUBSTAT_INCREMENTS[substat_1][6] * 5)
  775. if substat_2 is not None:
  776. substats.append(substat_2)
  777. efficiency += substat_2_value / float(SUBSTAT_INCREMENTS[substat_2][6] * 5)
  778. if substat_3 is not None:
  779. substats.append(substat_3)
  780. efficiency += substat_3_value / float(SUBSTAT_INCREMENTS[substat_3][6] * 5)
  781. if substat_4 is not None:
  782. substats.append(substat_4)
  783. efficiency += substat_4_value / float(SUBSTAT_INCREMENTS[substat_4][6] * 5)
  784. efficiency = efficiency / 2.8 * 100
  785. max_efficiency = get_max_efficiency(substats, efficiency, level, stars, original_quality)
  786. if efficiency > 100:
  787. efficiency = 100;
  788. if max_efficiency > 100:
  789. max_efficiency = 100;
  790. 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))
  791. db.commit()
  792. """
  793. calculates the max efficiency of a rune.
  794. :param substats: Array of substat types, dont include empty ones.
  795. :param efficiency: Current rune efficiency.
  796. :param level: Current rune level.
  797. :param stars: Rune stars.
  798. :param quality: Rune original quality.
  799. :return Max. efficiency.
  800. """
  801. def get_max_efficiency(substats, efficiency, level, stars, quality):
  802. STAT_HP = 1
  803. STAT_HP_PCT = 2
  804. STAT_ATK = 3
  805. STAT_ATK_PCT = 4
  806. STAT_DEF = 5
  807. STAT_DEF_PCT = 6
  808. STAT_SPD = 8
  809. STAT_CRIT_RATE_PCT = 9
  810. STAT_CRIT_DMG_PCT = 10
  811. STAT_RESIST_PCT = 11
  812. STAT_ACCURACY_PCT = 12
  813. SUBSTAT_INCREMENTS = {
  814. # [stat][stars]: value
  815. STAT_HP: {
  816. 1: 60,
  817. 2: 105,
  818. 3: 165,
  819. 4: 225,
  820. 5: 300,
  821. 6: 375,
  822. },
  823. STAT_HP_PCT: {
  824. 1: 2,
  825. 2: 3,
  826. 3: 5,
  827. 4: 6,
  828. 5: 7,
  829. 6: 8,
  830. },
  831. STAT_ATK: {
  832. 1: 4,
  833. 2: 5,
  834. 3: 8,
  835. 4: 10,
  836. 5: 15,
  837. 6: 20,
  838. },
  839. STAT_ATK_PCT: {
  840. 1: 2,
  841. 2: 3,
  842. 3: 5,
  843. 4: 6,
  844. 5: 7,
  845. 6: 8,
  846. },
  847. STAT_DEF: {
  848. 1: 4,
  849. 2: 5,
  850. 3: 8,
  851. 4: 10,
  852. 5: 15,
  853. 6: 20,
  854. },
  855. STAT_DEF_PCT: {
  856. 1: 2,
  857. 2: 3,
  858. 3: 5,
  859. 4: 6,
  860. 5: 7,
  861. 6: 8,
  862. },
  863. STAT_SPD: {
  864. 1: 1,
  865. 2: 2,
  866. 3: 3,
  867. 4: 4,
  868. 5: 5,
  869. 6: 6,
  870. },
  871. STAT_CRIT_RATE_PCT: {
  872. 1: 1,
  873. 2: 2,
  874. 3: 3,
  875. 4: 4,
  876. 5: 5,
  877. 6: 6,
  878. },
  879. STAT_CRIT_DMG_PCT: {
  880. 1: 2,
  881. 2: 3,
  882. 3: 4,
  883. 4: 5,
  884. 5: 6,
  885. 6: 7,
  886. },
  887. STAT_RESIST_PCT: {
  888. 1: 2,
  889. 2: 3,
  890. 3: 5,
  891. 4: 6,
  892. 5: 7,
  893. 6: 8,
  894. },
  895. STAT_ACCURACY_PCT: {
  896. 1: 2,
  897. 2: 3,
  898. 3: 5,
  899. 4: 6,
  900. 5: 7,
  901. 6: 8,
  902. },
  903. }
  904. UPGRADE_VALUES = {
  905. rune_type: {
  906. stars: value/level_data[6]
  907. for stars, value in level_data.items()
  908. }
  909. for rune_type, level_data in SUBSTAT_INCREMENTS.items()
  910. }
  911. #substat_upgrades_remaining = (4 - math.floor((min(level, 12) / 3))) - (3 - quality)
  912. substat_upgrades_remaining = (4 - math.floor((min(level, 12) / 3))) - max((3 - quality), 0)
  913. new_stats = max(min(4 - len(substats), substat_upgrades_remaining), 0)
  914. old_stats = substat_upgrades_remaining - new_stats
  915. if old_stats > 0:
  916. # we can repeatedly upgrade the most value of the existing stats
  917. best_stat = max(
  918. 0, # ensure max() doesn't error if we only have one stat
  919. *[UPGRADE_VALUES[stat][stars] for stat in substats]
  920. )
  921. efficiency += best_stat * old_stats * 0.2 / 2.8 * 100
  922. if new_stats:
  923. # add the top N stats
  924. available_upgrades = sorted(
  925. [
  926. upgrade_value[stars]
  927. for stat, upgrade_value in UPGRADE_VALUES.items()
  928. if stat not in substats
  929. ],
  930. reverse=True
  931. )
  932. efficiency += sum(available_upgrades[:new_stats]) * 0.2 / 2.8 * 100
  933. return efficiency
  934. """
  935. Parses rune craft item data (table rune_craft).
  936. :param db: Sqlite database connection.
  937. :param data: Data in json format.
  938. """
  939. def parseRuneCraft(db, data):
  940. print("Parsing rune craft itmes...")
  941. uid = data["wizard_info"]["wizard_id"]
  942. for item in data["rune_craft_item_list"]:
  943. id = item["craft_item_id"]
  944. type = item["craft_type"]
  945. value = item["sell_value"]
  946. info = str(item["craft_type_id"])
  947. """
  948. info : 5 or 6 digit number: RRSSQ
  949. RR: Rune
  950. SS: Stat
  951. Q: Quality
  952. """
  953. quality = int(info[-1:])
  954. stat = int(info[-4:-2])
  955. rune = int(info[:-4])
  956. insert(db, "rune_craft", (uid, id, type, quality, rune, stat, value))
  957. """
  958. Parses guild data (tables guild, guild_member).
  959. :param db: Sqlite database connection.
  960. :param data: Data in json format.
  961. """
  962. def parseGuild(db, data):
  963. print("Parsing guild...")
  964. if len(data["guild"]["guild_info"]) < 1:
  965. return
  966. guild = data["guild"]["guild_info"]
  967. id = guild["guild_id"]
  968. name = guild["name"]
  969. level = guild["level"]
  970. experience = guild["experience"]
  971. recruiting = guild["recruit_status"]
  972. members = guild["member_now"]
  973. leader = guild["master_wizard_id"]
  974. comment = guild["comment"]
  975. notice = guild["notice"]
  976. insert(db, "guild", (id, name, level, experience, recruiting, members, leader, comment, notice))
  977. # Single quates ahead, dirty fix
  978. for k, member in data["guild"]["guild_members"].items():
  979. m = json.loads(str(member).replace("'", '"'))
  980. id = m["wizard_id"]
  981. guild = member["guild_id"]
  982. grade = member["grade"]
  983. name = member["wizard_name"]
  984. level = member["wizard_level"]
  985. rating = member["rating_id"]
  986. arena_score = member["arena_score"]
  987. joined = member["join_timestamp"]
  988. last_login = member["last_login_timestamp"]
  989. in_war = 0 # Checked later
  990. has_defense = 0 # Checked later
  991. insert(db, "guild_member", (id, guild, grade, name, level, rating, arena_score, joined, last_login, in_war, has_defense))
  992. cursor = db.cursor()
  993. for war in data["guildwar_member_list"]:
  994. cursor.execute("UPDATE guild_member SET in_war = 1 WHERE guild = ? AND id = ?;", (war["guild_id"], war["wizard_id"]))
  995. for defense in data["guild_member_defense_list"]:
  996. if len(defense["unit_list"]) > 0:
  997. cursor.execute("UPDATE guild_member SET has_defense = 1 WHERE id = '" + str(defense["wizard_id"]) + "';")
  998. db.commit()
  999. cursor.close()
  1000. """
  1001. Deletes teams whose members no longer exists.
  1002. :param db: Sqlite database connection.
  1003. """
  1004. def reconfigureTeams(db):
  1005. print("Fixing teams...")
  1006. uid = data["wizard_info"]["wizard_id"]
  1007. cursor = db.cursor()
  1008. 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 = " + str(uid) + ")) AND uid = " + str(uid) + ";")
  1009. cursor.execute("DELETE FROM team_unit WHERE unit NOT IN (SELECT DISTINCT id FROM unit) OR team NOT IN (SELECT DISTINCT id FROM team);")
  1010. db.commit()
  1011. cursor.close()
  1012. """
  1013. Begin script
  1014. """
  1015. data = readData()
  1016. key = readKey()
  1017. db = openDatabase()
  1018. if verifyKey(db, data, key) == False:
  1019. print("Invalid API KEY...")
  1020. sys.exit(-1)
  1021. else:
  1022. clearData(db, data)
  1023. parsePlayer(db, data)
  1024. parseScenarios(db, data)
  1025. parseDefense(db, data)
  1026. parseBuildings(db, data)
  1027. parseDecorations(db, data)
  1028. # TODO homunculus_skill_list
  1029. parseUnits(db, data)
  1030. parseSummonSpecial(db, data)
  1031. parseInventory(db, data)
  1032. parseRunes(db, data)
  1033. parseRuneCraft(db, data)
  1034. parseGuild(db, data)
  1035. reconfigureTeams(db)
  1036. closeDatabase(db)
  1037. sys.exit(0);