idlechampchampionspage.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. import subprocess
  9. import filecmp
  10. import os
  11. COMPARE = True
  12. POST = False
  13. REDOWNLOAD = False
  14. SHOW_CHANGES = False
  15. _summary = None
  16. if POST:
  17. instance = ICAccount()
  18. instance.login()
  19. # filename = '/home/txtsd/.local/share/Steam/steamapps/common/IdleChampions/IdleDragons_Data/StreamingAssets/downloaded_files/cached_definitions.json'
  20. filename = '/tmp/cached_definitions.json'
  21. if REDOWNLOAD or not os.path.isfile(filename):
  22. result = requests.get('http://master.idlechampions.com/~idledragons/post.php?call=getdefinitions')
  23. with open(filename, 'w') as f:
  24. if result.status_code == 200:
  25. f.write(result.text)
  26. with open(filename) as f:
  27. file = f.read()
  28. js = json.loads(file)
  29. js_graphic = js['graphic_defines']
  30. js_attack = js['attack_defines']
  31. js_hero = js['hero_defines']
  32. js_hero_skin = js['hero_skin_defines']
  33. js_upgrade = js['upgrade_defines']
  34. js_premium_item = js['premium_item_defines']
  35. js_sound = js['sound_defines']
  36. js_buff = js['buff_defines']
  37. js_loot = js['loot_defines']
  38. js_achievement = js['achievement_defines']
  39. js_ability = js['ability_defines']
  40. js_effect = js['effect_defines']
  41. js_changelog = js['changelog_defines']
  42. js_text = js['text_defines']
  43. js_chest_type = js['chest_type_defines']
  44. js_effect_key = js['effect_key_defines']
  45. js_tutorial_state = js['tutorial_state_defines']
  46. js_game_rule = js['game_rule_defines']
  47. js_news = js['news_defines']
  48. js_language = js['language_defines']
  49. js_familiar = js['familiar_defines']
  50. temp_count = 0
  51. for effect in js_upgrade:
  52. if '{' in effect['effect']:
  53. # print(effect)
  54. str_effect = effect['effect']
  55. _effect = effect['effect'].replace("'", "\'")
  56. # print(_effect)
  57. # effect['effect'] = effect['effect'].replace('\"', '')
  58. temp = json.loads(_effect)
  59. # print(temp)
  60. # effect['effect'] = None
  61. # effect['effect'] = {}
  62. # js_upgrade.remove(effect)
  63. effect['effect'] = temp
  64. # js_upgrade.append(effect)
  65. # pprint(effect)
  66. # pprint(js_upgrade)
  67. # exit()
  68. breakout = 0
  69. wikitable = '''
  70. [[Champions]] fight [[monsters]] in [[Idle Champions of the Forgotten Realms]].
  71. Champions have specializations and can equip [[gear]].
  72. Strategically place them according to a [[Formation Strategy]] to overwhelm your enemies!
  73. == Champions list ==
  74. {{#vardefine:size|35px}}
  75. {| class="wikitable sortable" style="text-align:center"
  76. |-
  77. ! Slot
  78. ! data-sort-type="number"|<abbr title="Initial cost of the champion">Cost</abbr>
  79. !
  80. ! Name
  81. ! data-sort-type="number"|<abbr title="Multiplied Bonus of all 'Damage' abilities">Damage
  82. ! data-sort-type="number"|<abbr title="Multiplied Bonus of all 'Damage All' abilities">Damage All
  83. ! Age
  84. ! Race
  85. ! Class
  86. ! Alignment
  87. ! data-sort-type="number"|<abbr title="Strength">Str</abbr>
  88. ! data-sort-type="number"|<abbr title="Dexterity">Dex</abbr>
  89. ! data-sort-type="number"|<abbr title="Constitution">Con</abbr>
  90. ! data-sort-type="number"|<abbr title="Intelligence">Int</abbr>
  91. ! data-sort-type="number"|<abbr title="Wisdom">Wis</abbr>
  92. ! data-sort-type="number"|<abbr title="Charisma">Cha</abbr>
  93. ! data-sort-type="number"|<abbr title="Cooldown of the champion's base attack">Base CD</abbr>
  94. ! data-sort-type="number"|<abbr title="Cooldown of the champion's ultimate attack">Ult CD</abbr>
  95. '''
  96. for hero in js_hero:
  97. if not re.search('^E\d', hero['name']):
  98. row = '|-' + '\n'
  99. row += '| ' + str(hero['seat_id']) + '\n'
  100. row += '| ' + ('{0:.2E}'.format(Decimal(hero['base_cost'])) if (int(hero['base_cost']) / 100) > 1 else hero['base_cost']).replace('E+', 'e') + '\n'
  101. row += '| ' + '{{{{Icon-Link|{name}|size={{{{#var:size}}}}|notext=yes}}}}'.format(name=hero['name']) + '\n'
  102. row += '| ' + '[[{name}]]'.format(name=hero['name']) + '\n'
  103. row += '| ' + '{{{{:{name}|include=damage}}}}'.format(name=hero['name']) + '\n'
  104. row += '| ' + '{{{{:{name}|include=damageAll}}}}'.format(name=hero['name']) + '\n'
  105. row += '| ' + '{{{{:{name}|include=age}}}}'.format(name=hero['name']) + '\n'
  106. row += '| ' + '{{{{:{name}|include=race}}}}'.format(name=hero['name']) + '\n'
  107. row += '| ' + '{{{{:{name}|include=class}}}}'.format(name=hero['name']) + '\n'
  108. row += '| ' + '{{{{:{name}|include=alignment}}}}'.format(name=hero['name']) + '\n'
  109. row += '| ' + '{{{{:{name}|include=str}}}}'.format(name=hero['name']) + '\n'
  110. row += '| ' + '{{{{:{name}|include=dex}}}}'.format(name=hero['name']) + '\n'
  111. row += '| ' + '{{{{:{name}|include=con}}}}'.format(name=hero['name']) + '\n'
  112. row += '| ' + '{{{{:{name}|include=int}}}}'.format(name=hero['name']) + '\n'
  113. row += '| ' + '{{{{:{name}|include=wis}}}}'.format(name=hero['name']) + '\n'
  114. row += '| ' + '{{{{:{name}|include=cha}}}}'.format(name=hero['name']) + '\n'
  115. row += '| ' + '{{{{:{name}|include=base_cd}}}}'.format(name=hero['name']) + '\n'
  116. row += '| ' + '{{{{:{name}|include=ult_cd}}}}'.format(name=hero['name']) + '\n'
  117. wikitable += (row + '\n')
  118. # Wikitable end
  119. wikitable += '|}\n'
  120. wikitable += '''
  121. {{Navbox-Champions}}
  122. {{Navbox-IdleChampions}}
  123. [[Category:Champions]]'''
  124. with open('output/champions.txt', 'w') as f:
  125. f.write(wikitable)
  126. if COMPARE:
  127. dir_path = os.path.dirname(os.path.realpath(__file__))
  128. if not os.path.isdir(os.path.join(dir_path, 'output')):
  129. os.makedirs(os.path.join(dir_path, 'output'))
  130. main_file = os.path.join(dir_path, 'output/champions.txt')
  131. posted_file = os.path.join(dir_path, 'output/posted/champions.txt')
  132. try:
  133. result = filecmp.cmp(main_file, posted_file, shallow=False)
  134. except FileNotFoundError as e:
  135. print('No source found')
  136. result = None
  137. if result is not None:
  138. if result:
  139. print('No changes')
  140. else:
  141. print('Changes detected!')
  142. if SHOW_CHANGES:
  143. result = subprocess.run(['git', 'diff', '--no-index', posted_file, main_file])
  144. if POST:
  145. if _summary is None:
  146. _summary = input('Enter change summary: ')
  147. EDIT_PARAMS = {
  148. 'action': 'edit',
  149. 'title': 'Champions',
  150. 'text': wikitable,
  151. 'bot': '1',
  152. 'nocreate': '1',
  153. 'summary': _summary
  154. }
  155. print('Posting...')
  156. R2 = instance.post(data=EDIT_PARAMS)
  157. if R2.status_code == 200:
  158. print('Success!')
  159. with open('output/posted/champions.txt', 'w') as g:
  160. g.write(wikitable)
  161. else:
  162. print('FAIL!')