Steven Smith revised this gist . Go to revision
1 file changed, 34 insertions
get_world_quests.py(file created)
| @@ -0,0 +1,34 @@ | |||
| 1 | + | #!/usr/bin/env python3 | |
| 2 | + | import requests,json | |
| 3 | + | ||
| 4 | + | page = requests.get("http://www.wowhead.com/world-quests/na").text | |
| 5 | + | datasets,worldquest_raw = page.split("});\n\n//]]>")[0].split("\nvar lvWorldQuests") | |
| 6 | + | datasets = [n.strip() for n in datasets.split("var _ = {};")][1:] | |
| 7 | + | worldquests = json.loads(worldquest_raw.split("parent: 'list', data: ",1)[1].split("});\n\n//]]>",1)[0]) | |
| 8 | + | ||
| 9 | + | wq_items, wq_quests, wq_factions = {},{},{} | |
| 10 | + | wq_types = {1: "Profession Quest", 2: "World Quest", 3: "PVP World Quest", 4: "Pet Battle", 5: "Emissary (Faction) Quest", 6: "Dungeon World Quest", 7: "?? Maybe world boss", 8: "Raid World Quest"} | |
| 11 | + | ||
| 12 | + | for item in datasets[0].split(";")[:-3]: | |
| 13 | + | wq_items[int(item.split("_[",1)[1].split("]={",1)[0])] = json.loads(item.split("]=",1)[1]) | |
| 14 | + | ||
| 15 | + | for quest in datasets[1].split(";")[:-3]: | |
| 16 | + | wq_quests[int(quest.split("_[",1)[1].split("]={",1)[0])] = json.loads(quest.split("]=",1)[1]) | |
| 17 | + | ||
| 18 | + | for faction in datasets[3].split(";")[:-3]: | |
| 19 | + | wq_factions[int(faction.split("_[",1)[1].split("]={",1)[0])] = json.loads(faction.split("]=",1)[1]) | |
| 20 | + | ||
| 21 | + | for wq in worldquests: | |
| 22 | + | for n,f in enumerate(wq["factions"]): | |
| 23 | + | if f in wq_factions: | |
| 24 | + | wq["factions"][n] = {"id": f, "data": wq_factions[f]} | |
| 25 | + | if wq["rewards"]: | |
| 26 | + | if "items" in wq["rewards"]: | |
| 27 | + | for item in wq["rewards"]["items"]: | |
| 28 | + | if item["id"] in wq_items: | |
| 29 | + | item["data"] = wq_items[item["id"]] | |
| 30 | + | if wq["worldquesttype"] in wq_types: | |
| 31 | + | wq["worldquesttype"] = {"id": wq["worldquesttype"], "label": wq_types[wq["worldquesttype"]]} | |
| 32 | + | wq["data"] = wq_quests[wq["id"]] | |
| 33 | + | ||
| 34 | + | print(json.dumps(worldquests,indent=4)) | |
Newer
Older