idlechampwebreqlogrip.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. import json
  2. from pprint import pprint
  3. import re
  4. from collections import OrderedDict
  5. import math
  6. from decimal import Decimal
  7. from idlechampaccount import ICAccount
  8. webreqlog_path = '/home/txtsd/.local/share/Steam/steamapps/common/IdleChampions/IdleDragons_Data/StreamingAssets/downloaded_files/webRequestLog.txt'
  9. # webreqlog_path = '/tmp/webRequestLog.txt'
  10. with open(webreqlog_path) as f:
  11. webreqlog = f.read()
  12. search = re.search('({"success":true,"details":{.*})', webreqlog)
  13. # search = re.search('{"success":true,"graphic_defines":[.*', webreqlog)
  14. js = json.loads(search.group())
  15. js_adventure_defines = js['defines']['adventure_defines']
  16. js_adventure_area_defines = js['defines']['adventure_area_defines']
  17. js_background_defines = js['defines']['background_defines']
  18. js_campaign_defines = js['defines']['campaign_defines']
  19. js_location_defines = js['defines']['location_defines']
  20. js_monster_defines = js['defines']['monster_defines']
  21. js_quest_defines = js['defines']['quest_defines']
  22. js_cinematics_defines = js['defines']['cinematics_defines']
  23. js_distraction_defines = js['defines']['distraction_defines']
  24. js_reset_currency_defines = js['defines']['reset_currency_defines']
  25. js_reset_tier_defines = js['defines']['reset_tier_defines']
  26. js_reset_upgrade_defines = js['defines']['reset_upgrade_defines']
  27. if 'challenge_set_defines' in js['defines']:
  28. js_challenge_set_defines = js['defines']['challenge_set_defines']
  29. js_time_gates = json.loads('[' + json.dumps(js['details']['time_gates']) + ']')
  30. js_event_details = js['details']['event_details']
  31. js_package_deals = js['details']['package_deals']
  32. js_promotions = js['details']['promotions']
  33. # For single adventure files
  34. per_adventure_adventure_defines = []
  35. per_adventure_adventure_area_defines = []
  36. per_adventure_background_defines = []
  37. per_adventure_campaign_defines = []
  38. per_adventure_location_defines = []
  39. per_adventure_monster_defines = []
  40. per_adventure_quest_defines = []
  41. per_adventure_cinematics_defines = []
  42. per_adventure_distraction_defines = []
  43. per_adventure_reset_currency_defines = []
  44. per_adventure_reset_tier_defines = []
  45. per_adventure_reset_upgrade_defines = []
  46. per_adventure_challenge_set_defines = []
  47. per_adventure_time_gates = []
  48. per_adventure_event_details = []
  49. per_adventure_package_deals = []
  50. per_adventure_promotions = []
  51. # Read files and load data
  52. adventure_defines = []
  53. with open('json/{file}.json'.format(file='adventure_defines'), 'r') as f:
  54. adventure_defines = json.loads(f.read())
  55. adventure_area_defines = []
  56. with open('json/{file}.json'.format(file='adventure_area_defines'), 'r') as f:
  57. adventure_area_defines = json.loads(f.read())
  58. background_defines = []
  59. with open('json/{file}.json'.format(file='background_defines'), 'r') as f:
  60. background_defines = json.loads(f.read())
  61. campaign_defines = []
  62. with open('json/{file}.json'.format(file='campaign_defines'), 'r') as f:
  63. campaign_defines = json.loads(f.read())
  64. location_defines = []
  65. with open('json/{file}.json'.format(file='location_defines'), 'r') as f:
  66. location_defines = json.loads(f.read())
  67. monster_defines = []
  68. with open('json/{file}.json'.format(file='monster_defines'), 'r') as f:
  69. monster_defines = json.loads(f.read())
  70. quest_defines = []
  71. with open('json/{file}.json'.format(file='quest_defines'), 'r') as f:
  72. quest_defines = json.loads(f.read())
  73. cinematics_defines = []
  74. with open('json/{file}.json'.format(file='cinematics_defines'), 'r') as f:
  75. cinematics_defines = json.loads(f.read())
  76. distraction_defines = []
  77. with open('json/{file}.json'.format(file='distraction_defines'), 'r') as f:
  78. distraction_defines = json.loads(f.read())
  79. reset_currency_defines = []
  80. with open('json/{file}.json'.format(file='reset_currency_defines'), 'r') as f:
  81. reset_currency_defines = json.loads(f.read())
  82. reset_tier_defines = []
  83. with open('json/{file}.json'.format(file='reset_tier_defines'), 'r') as f:
  84. reset_tier_defines = json.loads(f.read())
  85. reset_upgrade_defines = []
  86. with open('json/{file}.json'.format(file='reset_upgrade_defines'), 'r') as f:
  87. reset_upgrade_defines = json.loads(f.read())
  88. challenge_set_defines = []
  89. if 'challenge_set_defines' in js['defines']:
  90. with open('json/{file}.json'.format(file='challenge_set_defines'), 'r') as f:
  91. challenge_set_defines = json.loads(f.read())
  92. time_gates = []
  93. with open('json/{file}.json'.format(file='time_gates'), 'r') as f:
  94. time_gates = json.loads(f.read())
  95. event_details = []
  96. with open('json/{file}.json'.format(file='event_details'), 'r') as f:
  97. event_details = json.loads(f.read())
  98. package_deals = []
  99. with open('json/{file}.json'.format(file='package_deals'), 'r') as f:
  100. package_deals = json.loads(f.read())
  101. promotions = []
  102. with open('json/{file}.json'.format(file='promotions'), 'r') as f:
  103. promotions = json.loads(f.read())
  104. # Write old + new data to files
  105. for item in js_adventure_defines:
  106. if item not in adventure_defines:
  107. adventure_defines.append(item)
  108. per_adventure_adventure_defines.append(item)
  109. with open('json/{file}.json'.format(file='adventure_defines'), 'w+') as f:
  110. f.write(json.dumps(adventure_defines))
  111. for item in js_adventure_area_defines:
  112. if item not in adventure_area_defines:
  113. adventure_area_defines.append(item)
  114. per_adventure_adventure_area_defines.append(item)
  115. with open('json/{file}.json'.format(file='adventure_area_defines'), 'w+') as f:
  116. f.write(json.dumps(adventure_area_defines))
  117. for item in js_background_defines:
  118. if item not in background_defines:
  119. background_defines.append(item)
  120. per_adventure_background_defines.append(item)
  121. with open('json/{file}.json'.format(file='background_defines'), 'w+') as f:
  122. f.write(json.dumps(background_defines))
  123. for item in js_campaign_defines:
  124. if item not in campaign_defines:
  125. campaign_defines.append(item)
  126. per_adventure_campaign_defines.append(item)
  127. with open('json/{file}.json'.format(file='campaign_defines'), 'w+') as f:
  128. f.write(json.dumps(campaign_defines))
  129. for item in js_location_defines:
  130. if item not in location_defines:
  131. location_defines.append(item)
  132. per_adventure_location_defines.append(item)
  133. with open('json/{file}.json'.format(file='location_defines'), 'w+') as f:
  134. f.write(json.dumps(location_defines))
  135. for item in js_monster_defines:
  136. if item not in monster_defines:
  137. monster_defines.append(item)
  138. per_adventure_monster_defines.append(item)
  139. with open('json/{file}.json'.format(file='monster_defines'), 'w+') as f:
  140. f.write(json.dumps(monster_defines))
  141. for item in js_quest_defines:
  142. if item not in quest_defines:
  143. quest_defines.append(item)
  144. per_adventure_quest_defines.append(item)
  145. with open('json/{file}.json'.format(file='quest_defines'), 'w+') as f:
  146. f.write(json.dumps(quest_defines))
  147. for item in js_cinematics_defines:
  148. if item not in cinematics_defines:
  149. cinematics_defines.append(item)
  150. per_adventure_cinematics_defines.append(item)
  151. with open('json/{file}.json'.format(file='cinematics_defines'), 'w+') as f:
  152. f.write(json.dumps(cinematics_defines))
  153. for item in js_distraction_defines:
  154. if item not in distraction_defines:
  155. distraction_defines.append(item)
  156. per_adventure_distraction_defines.append(item)
  157. with open('json/{file}.json'.format(file='distraction_defines'), 'w+') as f:
  158. f.write(json.dumps(distraction_defines))
  159. for item in js_reset_currency_defines:
  160. if item not in reset_currency_defines:
  161. reset_currency_defines.append(item)
  162. per_adventure_reset_currency_defines.append(item)
  163. with open('json/{file}.json'.format(file='reset_currency_defines'), 'w+') as f:
  164. f.write(json.dumps(reset_currency_defines))
  165. for item in js_reset_tier_defines:
  166. if item not in reset_tier_defines:
  167. reset_tier_defines.append(item)
  168. per_adventure_reset_tier_defines.append(item)
  169. with open('json/{file}.json'.format(file='reset_tier_defines'), 'w+') as f:
  170. f.write(json.dumps(reset_tier_defines))
  171. for item in js_reset_upgrade_defines:
  172. if item not in reset_upgrade_defines:
  173. reset_upgrade_defines.append(item)
  174. per_adventure_reset_upgrade_defines.append(item)
  175. with open('json/{file}.json'.format(file='reset_upgrade_defines'), 'w+') as f:
  176. f.write(json.dumps(reset_upgrade_defines))
  177. for item in js_challenge_set_defines:
  178. if item not in challenge_set_defines:
  179. challenge_set_defines.append(item)
  180. per_adventure_challenge_set_defines.append(item)
  181. with open('json/{file}.json'.format(file='challenge_set_defines'), 'w+') as f:
  182. f.write(json.dumps(challenge_set_defines))
  183. for item in js_time_gates:
  184. if item not in time_gates:
  185. time_gates.append(item)
  186. per_adventure_time_gates.append(item)
  187. with open('json/{file}.json'.format(file='time_gates'), 'w+') as f:
  188. f.write(json.dumps(time_gates))
  189. for item in js_event_details:
  190. if item not in event_details:
  191. event_details.append(item)
  192. per_adventure_event_details.append(item)
  193. with open('json/{file}.json'.format(file='event_details'), 'w+') as f:
  194. f.write(json.dumps(event_details))
  195. for item in js_package_deals:
  196. if item not in package_deals:
  197. package_deals.append(item)
  198. per_adventure_package_deals.append(item)
  199. with open('json/{file}.json'.format(file='package_deals'), 'w+') as f:
  200. f.write(json.dumps(package_deals))
  201. for item in js_promotions:
  202. if item not in promotions:
  203. promotions.append(item)
  204. per_adventure_promotions.append(item)
  205. with open('json/{file}.json'.format(file='promotions'), 'w+') as f:
  206. f.write(json.dumps(promotions))
  207. # Store all data in an adventure file separately
  208. if js_adventure_defines[0]['name'] == 'Free Play':
  209. per_adventure_filename = js_adventure_defines[1]['name'] + ' ' + js_adventure_defines[0]['name'] + '.json'
  210. else:
  211. per_adventure_filename = js_adventure_defines[0]['name'] + '.json'
  212. per_adventure_json = []
  213. per_adventure_json.append({'adventure_defines': per_adventure_adventure_defines})
  214. per_adventure_json.append({'adventure_area_defines': per_adventure_adventure_area_defines})
  215. per_adventure_json.append({'background_defines': per_adventure_background_defines})
  216. per_adventure_json.append({'campaign_defines': per_adventure_campaign_defines})
  217. per_adventure_json.append({'location_defines': per_adventure_location_defines})
  218. per_adventure_json.append({'monster_defines': per_adventure_monster_defines})
  219. per_adventure_json.append({'quest_defines': per_adventure_quest_defines})
  220. per_adventure_json.append({'cinematics_defines': per_adventure_cinematics_defines})
  221. per_adventure_json.append({'distraction_defines': per_adventure_distraction_defines})
  222. per_adventure_json.append({'reset_currency_defines': per_adventure_reset_currency_defines})
  223. per_adventure_json.append({'reset_tier_defines': per_adventure_reset_tier_defines})
  224. per_adventure_json.append({'reset_upgrade_defines': per_adventure_reset_upgrade_defines})
  225. per_adventure_json.append({'time_gates': per_adventure_time_gates})
  226. per_adventure_json.append({'event_details': per_adventure_event_details})
  227. per_adventure_json.append({'package_deals': per_adventure_package_deals})
  228. per_adventure_json.append({'promotions': per_adventure_promotions})
  229. with open('json/__{file}'.format(file=per_adventure_filename), 'w+') as f:
  230. f.write(json.dumps(per_adventure_json))