idlechampfamiliars.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import json
  2. from decimal import Decimal
  3. from idlechampaccount import ICAccount
  4. from pprint import pprint
  5. import os
  6. import filecmp
  7. COMPARE = True
  8. POST = False
  9. REDOWNLOAD = False
  10. _summary = None
  11. if POST:
  12. instance = ICAccount()
  13. instance.login()
  14. # filename = '/home/txtsd/.local/share/Steam/steamapps/common/IdleChampions/IdleDragons_Data/StreamingAssets/downloaded_files/cached_definitions.json'
  15. filename = '/tmp/cached_definitions.json'
  16. if REDOWNLOAD or not os.path.isfile(filename):
  17. result = requests.get('http://master.idlechampions.com/~idledragons/post.php?call=getdefinitions')
  18. with open(filename, 'w') as f:
  19. if result.status_code == 200:
  20. f.write(result.text)
  21. with open(filename) as f:
  22. file = f.read()
  23. js = json.loads(file)
  24. js_graphic = js['graphic_defines']
  25. js_attack = js['attack_defines']
  26. js_hero = js['hero_defines']
  27. js_hero_skin = js['hero_skin_defines']
  28. js_upgrade = js['upgrade_defines']
  29. js_premium_item = js['premium_item_defines']
  30. js_sound = js['sound_defines']
  31. js_buff = js['buff_defines']
  32. js_loot = js['loot_defines']
  33. js_achievement = js['achievement_defines']
  34. js_ability = js['ability_defines']
  35. js_effect = js['effect_defines']
  36. js_changelog = js['changelog_defines']
  37. js_text = js['text_defines']
  38. js_chest_type = js['chest_type_defines']
  39. js_effect_key = js['effect_key_defines']
  40. js_tutorial_state = js['tutorial_state_defines']
  41. js_game_rule = js['game_rule_defines']
  42. js_news = js['news_defines']
  43. js_language = js['language_defines']
  44. js_familiar = js['familiar_defines']
  45. page_text = '''
  46. Familiars are small creatures that can be purchased with either real money, or gems, that allow the player to automate [[clicking]] and leveling up [[Champions]].
  47. They get unlocked after having reached area 66 in any campaign.
  48. ==Clickrates==
  49. \'\'\'Clicking Monsters - 5 clicks per second\'\'\'
  50. *Up to six familiars can be assigned to clicking at a time.
  51. *If 3 or more are assigned, they will automatically pickup gold, quest items, event items, and the contents of the gem bag.
  52. *If 5 or more are assigned, they will automatically open the gem bag.
  53. *If 6 are assigned, they will automatically click distractions.
  54. *Familiars assigned to this task will always attack the frontmost enemy, as long as it is possible to deal damage to it via clicks (i.e. not log barricades or bosses with segmented health).
  55. \'\'\'Leveling Champions - 1 click per second\'\'\'
  56. *One familiar can be assigned per champion.
  57. *As they click in the same way as a person clicking the green button, if the level up system is set to purchase upgrades, they will not level up a champion until the upgrade can be afforded.
  58. \'\'\'Using Ultimates - 1 click per 30 seconds\'\'\'
  59. *Up to four familiars can be assigned to the ultimates bar at once.
  60. ==List of Familiars==
  61. {familiar_list}
  62. {{{{Navbox-IdleChampions}}}}
  63. [[Category:Game Mechanics]]'''
  64. familiar_text = ''
  65. for familiar in js_familiar:
  66. id_ = familiar['id']
  67. name = familiar['name']
  68. desc = familiar['description']
  69. cost = familiar['cost']
  70. prop = familiar['properties']
  71. fam = '''
  72. \'\'\'{name}\'\'\'
  73. {desc}
  74. ''Acquisition method: {cost}''
  75. '''
  76. if 'soft_currency' in cost:
  77. real_cost = str(cost['soft_currency']) + ' gems'
  78. # if (int(real_cost) / 1000) < 1:
  79. # real_cost = ('{0:.2E}'.format(cost['soft_currency'])).replace('E+', 'e')
  80. elif 'premium_item' in cost:
  81. for prem in js_premium_item:
  82. if prem['id'] == cost['premium_item']:
  83. real_cost = '$' + str(int(prem['cost']) / 100)
  84. elif 'show_only_if_owned' in prop:
  85. if name == 'Gift-Wrapped Mimic':
  86. real_cost = 'Participate in the first anniversary event.'
  87. elif name == 'Iris':
  88. real_cost = 'Part of the Founder\'s Pack.'
  89. fam = fam.format(
  90. name=name,
  91. desc=desc,
  92. cost=real_cost,
  93. )
  94. familiar_text += fam
  95. page_text = page_text.format(familiar_list=familiar_text)
  96. with open('output/familiars.txt', 'w') as f:
  97. f.write(page_text)
  98. if COMPARE:
  99. dir_path = os.path.dirname(os.path.realpath(__file__))
  100. if not os.path.isdir(os.path.join(dir_path, 'output')):
  101. os.makedirs(os.path.join(dir_path, 'output'))
  102. main_file = os.path.join(dir_path, 'output/familiars.txt')
  103. posted_file = os.path.join(dir_path, 'output/posted/familiars.txt')
  104. try:
  105. result = filecmp.cmp(main_file, posted_file, shallow=False)
  106. except FileNotFoundError as e:
  107. print('No source found')
  108. result = None
  109. if result is not None:
  110. if result:
  111. print('No changes')
  112. else:
  113. print('Changes detected!')
  114. if POST:
  115. if _summary is None:
  116. _summary = input('Enter change summary: ')
  117. EDIT_PARAMS = {
  118. 'action': 'edit',
  119. 'title': 'Familiars',
  120. 'text': page_text,
  121. 'bot': '1',
  122. 'nocreate': '1',
  123. 'summary': _summary
  124. }
  125. print('Posting...')
  126. R2 = instance.post(data=EDIT_PARAMS)
  127. if R2.status_code == 200:
  128. print('Success!')
  129. with open('output/posted/familiars.txt', 'w') as g:
  130. g.write(page_text)
  131. else:
  132. print('FAIL!')