idlechampchestspage.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. SHOW_CHANGES = False
  14. _summary = None
  15. if POST:
  16. instance = ICAccount()
  17. instance.login()
  18. # filename = '/home/txtsd/.local/share/Steam/steamapps/common/IdleChampions/IdleDragons_Data/StreamingAssets/downloaded_files/cached_definitions.json'
  19. filename = '/tmp/cached_definitions.json'
  20. if REDOWNLOAD or not os.path.isfile(filename):
  21. result = requests.get('http://master.idlechampions.com/~idledragons/post.php?call=getdefinitions')
  22. with open(filename, 'w') as f:
  23. if result.status_code == 200:
  24. f.write(result.text)
  25. promotions_filename = 'json/promotions.json'
  26. with open(filename) as f:
  27. file = f.read()
  28. with open(promotions_filename) as f:
  29. promotions_file = f.read()
  30. js = json.loads(file)
  31. js_promo = json.loads(promotions_file)
  32. js_graphic = js['graphic_defines']
  33. js_attack = js['attack_defines']
  34. js_hero = js['hero_defines']
  35. js_hero_skin = js['hero_skin_defines']
  36. js_upgrade = js['upgrade_defines']
  37. js_premium_item = js['premium_item_defines']
  38. js_sound = js['sound_defines']
  39. js_buff = js['buff_defines']
  40. js_loot = js['loot_defines']
  41. js_achievement = js['achievement_defines']
  42. js_ability = js['ability_defines']
  43. js_effect = js['effect_defines']
  44. js_changelog = js['changelog_defines']
  45. js_text = js['text_defines']
  46. js_chest_type = js['chest_type_defines']
  47. js_effect_key = js['effect_key_defines']
  48. js_tutorial_state = js['tutorial_state_defines']
  49. js_game_rule = js['game_rule_defines']
  50. js_news = js['news_defines']
  51. js_language = js['language_defines']
  52. js_familiar = js['familiar_defines']
  53. set_promo = set()
  54. for promo in js_promo:
  55. if promo['promotion_id'] not in set_promo:
  56. set_promo.add(promo['promotion_id'])
  57. print(promo)
  58. print(promo['promotion_id'], promo['name'])
  59. # # Stub status
  60. # page_text = '{{stub}}' + '\n' + page_text
  61. # page_text = (page_text + '\n' + footer)
  62. # # print(page_text)
  63. # with open('output/{filename}.txt'.format(filename=name), 'w') as f:
  64. # f.write(page_text)
  65. if COMPARE:
  66. dir_path = os.path.dirname(os.path.realpath(__file__))
  67. if not os.path.isdir(os.path.join(dir_path, 'output')):
  68. os.makedirs(os.path.join(dir_path, 'output'))
  69. main_file = os.path.join(dir_path, 'output/{filename}.txt'.format(filename=name))
  70. posted_file = os.path.join(
  71. dir_path, 'output/posted/{filename}.txt'.format(filename=name))
  72. try:
  73. result = filecmp.cmp(main_file, posted_file, shallow=False)
  74. except FileNotFoundError as e:
  75. print('{name}: No source found'.format(name=name))
  76. result = None
  77. if (result is not None) and (result == True):
  78. print('{name}: No changes'.format(name=name))
  79. else:
  80. print('{name}: Changes detected! <----------'.format(name=name))
  81. if SHOW_CHANGES:
  82. result = subprocess.run(['git', 'diff', '--no-index', posted_file, main_file])
  83. if POST:
  84. if _summary is None:
  85. _summary = input('Enter change summary: ')
  86. EDIT_PARAMS = {
  87. 'action': 'edit',
  88. 'title': name,
  89. 'text': page_text,
  90. 'bot': '1',
  91. 'summary': _summary
  92. # 'nocreate': '1',
  93. }
  94. print('{name}: Posting...'.format(name=name))
  95. R2 = instance.post(data=EDIT_PARAMS)
  96. if R2.status_code == 200:
  97. if 'error' not in R2.json():
  98. print('{name}: Success!'.format(name=name))
  99. with open('output/posted/{filename}.txt'.format(filename=name), 'w') as g:
  100. g.write(page_text)
  101. else:
  102. print('{name}: FAIL! Error Message: {error}'.format(
  103. name=name, error=R2.json()['error']['info']))
  104. else:
  105. print('{name}: FAIL!'.format(name=name))