forked from runelite/runelite-wiki-scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
npcs.py
47 lines (37 loc) · 1.13 KB
/
npcs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import traceback
import re
import mwparserfromhell as mw
import api
import util
from typing import *
import copy
def run():
npcs = {}
npc_pages = api.query_category("Monsters")
for name, page in npc_pages.items():
if name.startswith("Category:"):
continue
try:
code = mw.parse(page, skip_style_tags=True)
for (vid, version) in util.each_version("Infobox Monster", code):
if "removal" in version and str(version["removal"]).strip():
continue
doc = util.get_doc_for_id_string(name + str(vid), version, npcs)
if doc == None:
continue
util.copy("name", doc, version)
if not "name" in doc:
doc["name"] = name
scaling = util.has_template("Chambers of Xeric", code) or util.has_template("Theatre of Blood", code)
if not scaling:
for key in ["hitpoints"]:
try:
util.copy(key, doc, version, lambda x: int(x))
except ValueError:
print("NPC {} has an non integer {}".format(name, key))
except (KeyboardInterrupt, SystemExit):
raise
except:
print("NPC {} failed:".format(name))
traceback.print_exc()
util.write_json("npcs.json", "npcs.min.json", npcs)