idlechampadventures.py 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  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. adv_filename = 'json/adventure_defines.json'
  27. area_filename = 'json/adventure_area_defines.json'
  28. camp_filename = 'json/campaign_defines.json'
  29. monster_filename = 'json/monster_defines.json'
  30. with open(filename) as f:
  31. file = f.read()
  32. with open(adv_filename) as f:
  33. adv_file = f.read()
  34. with open(area_filename) as f:
  35. area_file = f.read()
  36. with open(camp_filename) as f:
  37. camp_file = f.read()
  38. with open(monster_filename) as f:
  39. monster_file = f.read()
  40. js = json.loads(file)
  41. js_adv = json.loads(adv_file)
  42. js_area = json.loads(area_file)
  43. js_camp = json.loads(camp_file)
  44. js_mon = json.loads(monster_file)
  45. js_graphic = js['graphic_defines']
  46. js_attack = js['attack_defines']
  47. js_hero = js['hero_defines']
  48. js_hero_skin = js['hero_skin_defines']
  49. js_upgrade = js['upgrade_defines']
  50. js_premium_item = js['premium_item_defines']
  51. js_sound = js['sound_defines']
  52. js_buff = js['buff_defines']
  53. js_loot = js['loot_defines']
  54. js_achievement = js['achievement_defines']
  55. js_ability = js['ability_defines']
  56. js_effect = js['effect_defines']
  57. js_changelog = js['changelog_defines']
  58. js_text = js['text_defines']
  59. js_chest_type = js['chest_type_defines']
  60. js_effect_key = js['effect_key_defines']
  61. js_tutorial_state = js['tutorial_state_defines']
  62. js_game_rule = js['game_rule_defines']
  63. js_news = js['news_defines']
  64. js_language = js['language_defines']
  65. js_familiar = js['familiar_defines']
  66. for mon in js_mon:
  67. if mon['name'] == 'Jarlaxle':
  68. temp = mon
  69. js_mon.remove(mon)
  70. temp['name'] = 'Jarlaxle (Monster)'
  71. js_mon.append(temp)
  72. # taglist = {}
  73. # for rule in js_game_rule:
  74. # if rule['rule_name'] == 'enemy_hover_tags':
  75. # for tag in rule['rule']['tags']:
  76. # taglist.update({tag: set()})
  77. # # pprint(taglist)
  78. # for monster in js_adv:
  79. # for tag in monster['tags']:
  80. # if tag in taglist:
  81. # taglist[tag].add(monster['name'])
  82. __js_adv = sorted(js_adv, key=lambda x: x['id'])
  83. __js_adv = sorted(__js_adv, key=lambda x: x['area_set_id'])
  84. __js_adv = sorted(__js_adv, key=lambda x: x['location_id'])
  85. __js_adv = sorted(__js_adv, key=lambda x: x['campaign_id'])
  86. __js_area = sorted(js_area, key=lambda x: x['id'])
  87. __js_area = sorted(__js_area, key=lambda x: x['area_id'])
  88. __js_area = sorted(__js_area, key=lambda x: x['area_set_id'])
  89. # pprint(__js_area)
  90. __js_mon = sorted(js_mon, key=lambda x: x['id'])
  91. # pprint(__js_adv)
  92. set_advs = set()
  93. def addtomonlist(dict_, m_id):
  94. for monster in __js_mon:
  95. if monster['id'] == m_id:
  96. if monster['name'] not in dict_:
  97. dict_[monster['name']] = []
  98. if sorted(set(monster['tags'])) not in dict_[monster['name']]:
  99. if dict_[monster['name']] == []:
  100. dict_[monster['name']].append(sorted(set(monster['tags'])))
  101. else:
  102. for tag in sorted(set(monster['tags'])):
  103. if tag not in dict_[monster['name']][0]:
  104. dict_[monster['name']][0].append(tag)
  105. # print(dict_)
  106. # print(monster, m_id, monster['name'])
  107. footer = '''
  108. {{Navbox-Adventures}}
  109. {{Navbox-IdleChampions}}
  110. [[Category:Adventures]]'''
  111. footer_event = '''
  112. {{Navbox-Adventures | event_state=expanded | locations_state = collapsed}}
  113. {{Navbox-IdleChampions}}
  114. [[Category:Events]] [[Category:Adventures]]'''
  115. for adv in __js_adv:
  116. if adv['id'] not in set_advs:
  117. set_advs.add(adv['id'])
  118. # print(json.dumps(adv))
  119. page_text = ''
  120. adv_text = ''
  121. # print(adv['id'], adv['name'])
  122. # print(adv['campaign_id'], adv['location_id'], adv['area_set_id'])
  123. # print('Description:', adv['description'])
  124. # print('Requirements:', adv['requirements_text'])
  125. # print('Objectives:', adv['objectives_text'])
  126. # print('Restrictions:', adv['restrictions_text'])
  127. # if not adv['rewards'] == []:
  128. # print('Rewards:', adv['rewards'])
  129. # if 'amount' in adv['rewards'][0]:
  130. # print('Rewards:', adv['rewards'][0]['reward'] + ': ' + str(adv['rewards'][0]['amount']))
  131. # elif 'crusader_id' in adv['rewards'][0]:
  132. # print('Rewards:', adv['rewards'][0]['reward'] + ': ' + str(adv['rewards'][0]['crusader_id']))
  133. # if not adv['costs'] == []:
  134. # print('Costs:', adv['costs'])
  135. # print('\n')
  136. # if adv['name'] == 'Free Play'
  137. adv_text += ('<onlyinclude><!--\n-->')
  138. adv_text += ('{{AdventureNew' + '\n')
  139. name = adv['name']
  140. if name == 'Free Play':
  141. for _adv in __js_adv:
  142. if adv['variant_adventure_id'] == _adv['id']:
  143. name = _adv['name'] + ' ' + name
  144. adv_text += ('| icon = ' + _adv['name'] + '\n')
  145. elif 'Free Play (' in name:
  146. for _adv in __js_adv:
  147. if adv['variant_adventure_id'] == _adv['id']:
  148. adv_text += ('| icon = ' + _adv['name'] + '\n')
  149. adv_text += ('| name = ' + name + '\n')
  150. adv_text += ('| description = ' + adv['description'] + '\n')
  151. requirements = adv['requirements_text']
  152. # print('1__', requirements)
  153. requirements = requirements.replace('\r\n', '\n')
  154. result1 = re.search('.*"(.*)"', requirements, re.MULTILINE | re.DOTALL)
  155. if result1:
  156. if result1.group(1) in [
  157. 'A Brief Escort through the Realm',
  158. 'A Brief Tour of the Realm',
  159. ]:
  160. replacement = '[[' + result1.group(1) + 's]]'
  161. else:
  162. replacement = '[[' + result1.group(1) + ']]'
  163. requirements = requirements.replace(result1.group(1), replacement)
  164. # print('2__', requirements)
  165. result2 = re.search('((Costs|Costs up to|Must have) \d+ (\w*.*)s to start)', requirements, re.MULTILINE | re.DOTALL)
  166. if result2:
  167. requirements = requirements.replace(result2.group(1), '')
  168. requirements = requirements[:-1]
  169. # requirements = requirements.replace('<br>', '\n')
  170. adv_text += ('| requirements = ' + requirements + '\n')
  171. if not adv['costs'] == []:
  172. if adv['costs'][0]['cost'] == 'event_tokens':
  173. adv_text += ('| cost = ' + str(adv['costs'][0]['amount']) + '\n')
  174. # if adv['costs'][0]['event_id'] == 18:
  175. # adv_text += ('| cost_type = ' + result2.group(2) + '\n')
  176. # if adv['costs'][0]['event_id'] == 23:
  177. # print('__3', requirements)
  178. # print('__3', name)
  179. adv_text += ('| cost_type = ' + result2.group(3) + '\n')
  180. adv_text += ('| objectives = ' + adv['objectives_text'] + '\n')
  181. adv_text += ('| restrictions = ' + adv['restrictions_text'] + '\n')
  182. if not adv['rewards'] == []:
  183. for reward in adv['rewards']:
  184. if reward['reward'] == 'red_rubies':
  185. adv_text += ('| gems = ' + str(reward['amount']) + '\n')
  186. elif reward['reward'] == 'claim_crusader':
  187. for hero in js_hero:
  188. if reward['crusader_id'] == hero['id']:
  189. adv_text += ('| championreward = ' + hero['name'] + '\n')
  190. elif reward['reward'] == 'chest':
  191. if 'chest_type_id' in reward:
  192. for chest in js_chest_type:
  193. if chest['id'] == reward['chest_type_id']:
  194. adv_text += ('| chest = {{ChestNew|name=' +
  195. chest['name'] + '}}' + '\n')
  196. elif 'chest_type_ids' in reward:
  197. for enum, chest_choice in enumerate(reward['chest_type_ids']):
  198. for chest in js_chest_type:
  199. if chest['id'] == chest_choice:
  200. one_chest = chest['name']
  201. one_chance = str(reward['chest_odds'][enum]) + '%'
  202. adv_text += ('| chest' + str(enum + 1) +
  203. '= {{ChestNew|name=' + one_chest + '|chance=' + one_chance + '}}' + '\n')
  204. if adv['campaign_id'] == 1:
  205. adv_text += ('| favor = ' + 'Torm' + '\n')
  206. elif adv['campaign_id'] == 2:
  207. adv_text += ('| favor = ' + 'Chauntea' + '\n')
  208. elif adv['campaign_id'] == 3:
  209. adv_text += ('| favor = ' + 'Kelemvor' + '\n')
  210. elif adv['campaign_id'] == 4:
  211. adv_text += ('| favor = ' + 'Leira' + '\n')
  212. elif adv['campaign_id'] == 5:
  213. adv_text += ('| favor = ' + 'Jergal' + '\n')
  214. elif adv['campaign_id'] == 6:
  215. adv_text += ('| favor = ' + 'Shar' + '\n')
  216. elif adv['campaign_id'] == 7:
  217. adv_text += ('| favor = ' + 'Oghma' + '\n')
  218. elif adv['campaign_id'] == 8:
  219. adv_text += ('| favor = ' + 'Auril' + '\n')
  220. elif adv['campaign_id'] == 9:
  221. adv_text += ('| favor = ' + 'Sune' + '\n')
  222. elif adv['campaign_id'] == 10:
  223. adv_text += ('| favor = ' + 'Umberlee' + '\n')
  224. elif adv['campaign_id'] == 11:
  225. adv_text += ('| favor = ' + 'Lliira' + '\n')
  226. elif adv['campaign_id'] == 12:
  227. adv_text += ('| favor = ' + 'Lathander' + '\n')
  228. elif adv['campaign_id'] == 13:
  229. adv_text += ('| favor = ' + 'Rillifane' + '\n')
  230. elif adv['campaign_id'] == 14:
  231. adv_text += ('| favor = ' + 'Gond' + '\n')
  232. elif adv['campaign_id'] == 15:
  233. adv_text += ('| favor = ' + 'Helm' + '\n')
  234. elif adv['campaign_id'] == 16:
  235. adv_text += ('| favor = ' + 'Waukeen' + '\n')
  236. elif adv['campaign_id'] == 17:
  237. adv_text += ('| favor = ' + 'Mystra' + '\n')
  238. elif adv['campaign_id'] == 18:
  239. adv_text += ('| favor = ' + 'Asmodeus' + '\n')
  240. elif adv['campaign_id'] == 19:
  241. adv_text += ('| favor = ' + 'Savra' + '\n')
  242. elif adv['campaign_id'] == 20:
  243. adv_text += ('| favor = ' + 'Azuth' + '\n')
  244. elif adv['campaign_id'] == 21:
  245. adv_text += ('| favor = ' + 'Tempus' + '\n')
  246. second_formation_logic = True
  247. if 'game_changes' in adv:
  248. check_for_formation_and_altered = set()
  249. for change in adv['game_changes']:
  250. check_for_formation_and_altered.add(change['type'])
  251. if 'name' in change:
  252. formation = change['name'].replace(' formation', '').replace(' Formation', '')
  253. if any(
  254. y in check_for_formation_and_altered for y in [
  255. 'slot_escort',
  256. 'blocked_heroes_by_area',
  257. 'slot_escort_by_area',
  258. 'initial_formation',
  259. ]
  260. ):
  261. # print('Altered Formation')
  262. formation = name.replace(' formation', '').replace(' Formation', '')
  263. adv_text += ('| formation = ' + formation + '\n')
  264. second_formation_logic = False
  265. elif 'formation' in check_for_formation_and_altered:
  266. adv_text += ('| formation = ' + formation + '\n')
  267. second_formation_logic = False
  268. if second_formation_logic:
  269. for campaign in js_camp:
  270. # print(campaign['id'])
  271. # print(adv['campaign_id'])
  272. if campaign['id'] == int(adv['campaign_id']):
  273. for change in campaign['game_changes']:
  274. if change['type'] == 'formation':
  275. if not change['name'] == 'Overwritten formation':
  276. formation = change['name'].replace(
  277. ' formation', '').replace(' Formation', '')
  278. adv_text += ('| formation = ' + formation + '\n')
  279. adv_text += '}}'
  280. adv_text += '<!--\n--></onlyinclude>'
  281. # print(adv_text)
  282. # print()
  283. intro = '\'\'\'{adv_name}\'\'\' is {adv_or_var} in the campaign [[{campaign}]].'
  284. for campaign in js_camp:
  285. if adv['campaign_id'] == campaign['id']:
  286. camp_name = campaign['name']
  287. if 'variant_adventure_id' in adv:
  288. for _adv in __js_adv:
  289. if adv['variant_adventure_id'] == _adv['id']:
  290. _name = _adv['name']
  291. intro_text = intro.format(
  292. adv_name=name,
  293. adv_or_var='one of the [[Variant]] [[Adventures]] of [[{_name}]]'.format(
  294. _name=_name),
  295. campaign=camp_name,
  296. )
  297. else:
  298. intro_text = intro.format(
  299. adv_name=name,
  300. adv_or_var='one of the [[Adventures]]',
  301. campaign=camp_name,
  302. )
  303. page_text = intro_text + page_text + '\n'
  304. page_text += adv_text
  305. variant_text = '<ul class="hlist">'
  306. _set_advs = set()
  307. for _adv in __js_adv:
  308. if _adv['id'] not in _set_advs:
  309. _set_advs.add(_adv['id'])
  310. if 'variant_adventure_id' in _adv:
  311. if _adv['variant_adventure_id'] == adv['id']:
  312. _name = _adv['name']
  313. if _name == 'Free Play':
  314. _name = adv['name'] + ' ' + _name
  315. variant_text += ('\n' + '<li>' +
  316. '{{{{:{name}}}}}'.format(name=_name) + '</li>')
  317. variant_text += ('\n' + '</ul>')
  318. if not variant_text == '<ul class="hlist">\n</ul>':
  319. variant_text = '\n' + '{{clear}}' + '\n' + '==Variants==' + '\n' + variant_text
  320. page_text += variant_text
  321. # print(page_text)
  322. # print()
  323. ######
  324. mobtable = '''\n\n==Wave Information==
  325. {| class="wikitable"
  326. !Area
  327. !Monsters
  328. !Types'''
  329. set_areas = set()
  330. for area in __js_area:
  331. # print(set_areas)
  332. if area['area_set_id'] == adv['area_set_id']:
  333. if area['id'] not in set_areas:
  334. set_areas.add(area['id'])
  335. # print(area['id'])
  336. if 'monsters' in area:
  337. # print(area['monsters'])
  338. if 'properties' in area:
  339. if 'monster_spawners' in area['properties']:
  340. # print(area['properties']['monster_spawners'])
  341. if not area['properties']['monster_spawners'] == {}:
  342. for key in area['properties']['monster_spawners']:
  343. # temp = area['properties']['monster_spawners']
  344. # print(area['properties'])
  345. # spawner = temp.popitem()[0]
  346. # print('monster_spawners', spawner, end='')
  347. pass
  348. # print('monster_spawners', key, end='')
  349. elif 'monster_generators' in area['properties']:
  350. if not area['properties']['monster_generators'] == {}:
  351. for key in area['properties']['monster_generators']:
  352. # temp = area['properties']['monster_generators']
  353. # print(area['properties'])
  354. # spawner = temp.popitem()[1]
  355. # print('monster_generators', spawner, end='')
  356. pass
  357. # print('monster_generators', key, end='')
  358. monlist = {}
  359. mobtable += ('\n' + '|-')
  360. mobtable += ('\n' + '|' + str(area['area_id']))
  361. static_boss = False
  362. static_bosses = {}
  363. for monster in area['monsters']:
  364. for _monster in __js_mon:
  365. if monster == _monster['id']:
  366. addtomonlist(monlist, _monster['id'])
  367. if area['monsters'] == []:
  368. # print('Detected unsuality', '<' + ('~'*100))
  369. if 'properties' in area:
  370. if 'include_monster_defs' in area['properties']:
  371. for mob_id in area['properties']['include_monster_defs']:
  372. for _monster in __js_mon:
  373. if (mob_id == _monster['id']) and (not mob_id == 1):
  374. addtomonlist(monlist, _monster['id'])
  375. # print(monlist)
  376. if 'static_monsters' in area['properties']:
  377. for static_mon in area['properties']['static_monsters']:
  378. addtomonlist(
  379. static_bosses, area['properties']['static_monsters'][static_mon]['monster_id'])
  380. static_boss = True
  381. elif not area['monsters'] == []:
  382. if 'properties' in area:
  383. if 'static_monsters' in area['properties']:
  384. for static_mon in area['properties']['static_monsters']:
  385. if 'boss' in area['properties']['static_monsters'][static_mon]:
  386. addtomonlist(
  387. static_bosses, area['properties']['static_monsters'][static_mon]['monster_id'])
  388. static_boss = True
  389. monlist_text = ''
  390. typelist = set()
  391. for listitem in sorted(monlist):
  392. monlist_text += ('[[' + listitem + ']]' + ', ')
  393. for _type in monlist[listitem]:
  394. for __type in _type:
  395. typelist.add(__type)
  396. monlist_text = monlist_text[:-2]
  397. mobtable += ('\n' + '|' + monlist_text)
  398. # Types
  399. for wave in sorted(monlist):
  400. typestring = ''
  401. for _type in sorted(typelist):
  402. # typestring += (_type.title() + ', ')
  403. typestring += ('{{TypeTag|' + _type + '}}')
  404. # typestring = typestring[:-2]
  405. mobtable += ('\n' + '|' + typestring)
  406. if static_boss == True:
  407. # Boss
  408. typelist = set()
  409. mobtable += '\n' + '|-'
  410. mobtable += ('\n' + '|' + '\'\'\'Boss\'\'\'')
  411. mobtable += ('\n' + '|')
  412. for boss in sorted(static_bosses):
  413. # print(boss)
  414. mobtable += ('\'\'\'[[' + boss + ']]\'\'\'' + ', ')
  415. for _type in static_bosses[boss]:
  416. for __type in _type:
  417. # print(typelist)
  418. # print(boss, __type)
  419. typelist.add(__type)
  420. mobtable = mobtable[:-2]
  421. # Types
  422. for boss in sorted(static_bosses):
  423. typestring = ''
  424. for _type in sorted(typelist):
  425. # typestring += (_type.title() + ', ')
  426. typestring += ('{{TypeTag|' + _type + '}}')
  427. # typestring = typestring[:-2]
  428. mobtable += ('\n' + '|' + typestring)
  429. elif 'waves' in area:
  430. wavelist_container = {}
  431. wavelist_container_text = ''
  432. for enum, wave in enumerate(area['waves']):
  433. wavelist = {}
  434. # wavelist = set()
  435. for monster in sorted(wave):
  436. for _monster in __js_mon:
  437. if monster == _monster['id']:
  438. addtomonlist(wavelist, _monster['id'])
  439. wavelist_container[enum + 1] = wavelist
  440. if len(wavelist_container) == 3:
  441. if wavelist_container[1] == wavelist_container[2]:
  442. wavelist_container_text = ''
  443. typelist = set()
  444. for listitem in sorted(wavelist_container[1]):
  445. wavelist_container_text += ('[[' + listitem + ']]' + ', ')
  446. for _type in wavelist_container[1][listitem]:
  447. for __type in _type:
  448. typelist.add(__type)
  449. wavelist_container_text = wavelist_container_text[:-2]
  450. mobtable += ('\n' + '|-')
  451. mobtable += ('\n' + '|' + str(area['area_id']))
  452. mobtable += ('\n' + '|')
  453. mobtable += wavelist_container_text
  454. # Types
  455. for wave in sorted(wavelist_container[1]):
  456. typestring = ''
  457. for _type in sorted(typelist):
  458. # typestring += (_type.title() + ', ')
  459. typestring += ('{{TypeTag|' + _type + '}}')
  460. # typestring = typestring[:-2]
  461. mobtable += ('\n' + '|' + typestring)
  462. if wavelist_container[1] == wavelist_container[2]:
  463. typelist = set()
  464. wavelist_container_text = ''
  465. mobtable += ('\n' + '|-')
  466. mobtable += ('\n' + '|' + '\'\'\'Boss\'\'\'')
  467. mobtable += ('\n' + '|')
  468. for listitem in sorted(wavelist_container[3]):
  469. wavelist_container_text += (
  470. '\'\'\'[[' + listitem + ']]\'\'\'' + ', ')
  471. for _type in wavelist_container[3][listitem]:
  472. for __type in _type:
  473. typelist.add(__type)
  474. wavelist_container_text = wavelist_container_text[:-2]
  475. mobtable += wavelist_container_text
  476. # Types
  477. for wave in sorted(wavelist_container[3]):
  478. typestring = ''
  479. for _type in sorted(typelist):
  480. # typestring += (_type.title() + ', ')
  481. typestring += ('{{TypeTag|' + _type + '}}')
  482. # typestring = typestring[:-2]
  483. mobtable += ('\n' + '|' + typestring)
  484. else:
  485. # If Wave1 != Wave2
  486. mobtable += ('\n' + '|-')
  487. mobtable += ('\n' + '|' + str(area['area_id']))
  488. wave_subtable = ('\n' + '|')
  489. wavelist_container = {}
  490. # Monsters
  491. for enum, wave in enumerate(area['waves']):
  492. wavelist = {}
  493. for monster in sorted(wave):
  494. for _monster in __js_mon:
  495. if monster == _monster['id']:
  496. addtomonlist(wavelist, _monster['id'])
  497. if enum in [0, 1]:
  498. wavelist_text = '\'\'Wave ' + str(enum + 1) + ':\'\' '
  499. typelist = set()
  500. for listitem in sorted(wavelist):
  501. wavelist_text += ('[[' + listitem + ']]' + ', ')
  502. for _type in wavelist[listitem]:
  503. for __type in _type:
  504. typelist.add(__type)
  505. wavelist_text = wavelist_text[:-2]
  506. wave_subtable += (wavelist_text + '\n')
  507. wave_subtable = wave_subtable[:-1]
  508. mobtable += wave_subtable
  509. # Types
  510. for enum, wave in enumerate(area['waves']):
  511. if enum in [0, 1]:
  512. typestring = '<ul class="hlist">\'\'Wave ' + \
  513. str(enum + 1) + ':\'\' '
  514. for _type in sorted(typelist):
  515. # typestring += (_type.title() + ', ')
  516. typestring += ('<li>{{TypeTag|' + _type + '}}</li>')
  517. # typestring = typestring[:-2]
  518. if enum == 0:
  519. mobtable += ('\n' + '|' + typestring + '</ul>')
  520. elif enum == 1:
  521. mobtable += ('\n' + typestring + '</ul>')
  522. # Bosses
  523. wave_subtable = ''
  524. wavelist_container = {}
  525. for enum, wave in enumerate(area['waves']):
  526. wavelist = {}
  527. for monster in sorted(wave):
  528. for _monster in __js_mon:
  529. if monster == _monster['id']:
  530. addtomonlist(wavelist, _monster['id'])
  531. if enum not in [0, 1]:
  532. typelist = set()
  533. wavelist_text = '\n' + '|-'
  534. wavelist_text += ('\n' + '|' + '\'\'\'Boss\'\'\'')
  535. wavelist_text += ('\n' + '|')
  536. for listitem in sorted(wavelist):
  537. wavelist_text += ('\'\'\'[[' +
  538. listitem + ']]\'\'\'' + ', ')
  539. for _type in wavelist[listitem]:
  540. for __type in _type:
  541. typelist.add(__type)
  542. wavelist_text = wavelist_text[:-2]
  543. wave_subtable += (wavelist_text + '\n')
  544. wave_subtable = wave_subtable[:-1]
  545. mobtable += wave_subtable
  546. # Types
  547. for enum, wave in enumerate(area['waves']):
  548. if enum not in [0, 1]:
  549. typestring = ''
  550. for _type in sorted(typelist):
  551. # typestring += (_type.title() + ', ')
  552. typestring += ('{{TypeTag|' + _type + '}}')
  553. # typestring = typestring[:-2]
  554. mobtable += ('\n' + '|' + typestring)
  555. # If only 2 waves
  556. elif len(wavelist_container) == 2:
  557. # If Wave1 == Wave2
  558. # Monsters
  559. if wavelist_container[1] == wavelist_container[2]:
  560. wavelist_container_text = ''
  561. typelist = set()
  562. for listitem in sorted(wavelist_container[1]):
  563. wavelist_container_text += ('[[' + listitem + ']]' + ', ')
  564. for _type in wavelist_container[1][listitem]:
  565. for __type in _type:
  566. typelist.add(__type)
  567. wavelist_container_text = wavelist_container_text[:-2]
  568. mobtable += ('\n' + '|-')
  569. mobtable += ('\n' + '|' + str(area['area_id']))
  570. mobtable += ('\n' + '|')
  571. mobtable += wavelist_container_text
  572. # Types
  573. for wave in sorted(wavelist_container[1]):
  574. typestring = ''
  575. for _type in sorted(wavelist_container[1][wave]):
  576. for __type in _type:
  577. # typestring += (__type.title() + ', ')
  578. typestring += ('{{TypeTag|' + __type + '}}')
  579. # typestring = typestring[:-2]
  580. mobtable += ('\n' + '|' + typestring)
  581. # If Wave1 != Wave2
  582. # And if Wave2 is a boss wave
  583. if not wavelist_container[1] == wavelist_container[2]:
  584. typelist = set()
  585. wavelist_container_text = ''
  586. if 'properties' in area:
  587. # If there is a boss in boss area
  588. if 'no_bosses_in_area' not in area['properties']:
  589. # Boss
  590. mobtable += ('\n' + '|-')
  591. mobtable += ('\n' + '|' + '\'\'\'Boss\'\'\'')
  592. mobtable += ('\n' + '|')
  593. for listitem in sorted(wavelist_container[2]):
  594. wavelist_container_text += (
  595. '\'\'\'[[' + listitem + ']]\'\'\'' + ', ')
  596. for _type in wavelist_container[2][listitem]:
  597. for __type in _type:
  598. typelist.add(__type)
  599. mobtable += wavelist_container_text
  600. # Types
  601. for wave in sorted(wavelist_container[2]):
  602. typestring = ''
  603. for _type in sorted(wavelist_container[2][wave]):
  604. for __type in _type:
  605. # typestring += (__type.title() + ', ')
  606. typestring += ('{{TypeTag|' + __type + '}}')
  607. # typestring = typestring[:-2]
  608. mobtable += ('\n' + '|' + typestring)
  609. elif len(wavelist_container) == 1:
  610. # Boss mode
  611. typelist = set()
  612. wavelist_container_text = ''
  613. mobtable += ('\n' + '|-')
  614. mobtable += ('\n' + '|' + str(area['area_id']) + ' \'\'\'Boss\'\'\'')
  615. mobtable += ('\n' + '|')
  616. for listitem in sorted(wavelist_container[1]):
  617. wavelist_container_text += (
  618. '\'\'\'[[' + listitem + ']]\'\'\'' + ', ')
  619. for _type in wavelist_container[1][listitem]:
  620. for __type in _type:
  621. typelist.add(__type)
  622. wavelist_container_text = wavelist_container_text[:-2]
  623. mobtable += wavelist_container_text
  624. # Types
  625. for wave in sorted(wavelist_container[1]):
  626. typestring = ''
  627. for _type in sorted(wavelist_container[1][wave]):
  628. for __type in _type:
  629. # typestring += (__type.title() + ', ')
  630. typestring += ('{{TypeTag|' + __type + '}}')
  631. # typestring = typestring[:-2]
  632. mobtable += ('\n' + '|' + typestring)
  633. else:
  634. print('Check area id:', area['id'])
  635. if len(mobtable) > 66:
  636. mobtable += ('\n' + '|}')
  637. page_text += mobtable
  638. # else:
  639. # print('AAAAAAHHHHHHHHHHHHHHHHH', adv['name'])
  640. # print(mobtable)
  641. ######
  642. # Stub status
  643. page_text = '{{stub}}' + '\n' + page_text
  644. # page_text = (page_text + '\n' + footer)
  645. if not adv['costs'] == []:
  646. for cost in adv['costs']:
  647. if 'cost' in cost:
  648. if cost['cost'] == 'event_tokens':
  649. page_text = (page_text + '\n' + footer_event)
  650. else:
  651. page_text = (page_text + '\n' + footer)
  652. # print(page_text)
  653. with open('output/{filename}.txt'.format(filename=name), 'w') as f:
  654. f.write(page_text)
  655. if COMPARE:
  656. dir_path = os.path.dirname(os.path.realpath(__file__))
  657. if not os.path.isdir(os.path.join(dir_path, 'output')):
  658. os.makedirs(os.path.join(dir_path, 'output'))
  659. main_file = os.path.join(dir_path, 'output/{filename}.txt'.format(filename=name))
  660. posted_file = os.path.join(
  661. dir_path, 'output/posted/{filename}.txt'.format(filename=name))
  662. try:
  663. result = filecmp.cmp(main_file, posted_file, shallow=False)
  664. except FileNotFoundError as e:
  665. print('{name}: No source found'.format(name=name))
  666. result = None
  667. if (result is not None) and (result == True):
  668. print('{name}: No changes'.format(name=name))
  669. else:
  670. print('{name}: Changes detected! <----------'.format(name=name))
  671. if SHOW_CHANGES:
  672. result = subprocess.run(['git', 'diff', '--no-index', posted_file, main_file])
  673. if POST:
  674. if _summary is None:
  675. _summary = input('Enter change summary: ')
  676. EDIT_PARAMS = {
  677. 'action': 'edit',
  678. 'title': name,
  679. 'text': page_text,
  680. 'bot': '1',
  681. 'summary': _summary
  682. # 'nocreate': '1',
  683. }
  684. print('{name}: Posting...'.format(name=name))
  685. R2 = instance.post(data=EDIT_PARAMS)
  686. if R2.status_code == 200:
  687. if 'error' not in R2.json():
  688. print('{name}: Success!'.format(name=name))
  689. with open('output/posted/{filename}.txt'.format(filename=name), 'w') as g:
  690. g.write(page_text)
  691. else:
  692. print('{name}: FAIL! Error Message: {error}'.format(
  693. name=name, error=R2.json()['error']['info']))
  694. else:
  695. print('{name}: FAIL!'.format(name=name))