-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathscrape_enchant_descriptions_new.py
73 lines (55 loc) · 1.87 KB
/
scrape_enchant_descriptions_new.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python3
import csv
import os
import sys
import json
from typing import List, Mapping, Set
import requests
if len(sys.argv) < 3:
raise Exception("Missing arguments, expected db_path, output_file_path")
input_db_path = sys.argv[1]
output_file_path = sys.argv[2]
branch = "wow_classic_beta"
def download_file(url, file_path):
if os.path.exists(file_path):
return
response = requests.get(url)
if response.status_code == 200:
with open(file_path, 'wb') as file:
file.write(response.content)
print(f"File downloaded successfully to {file_path}")
else:
print(f"Failed to download file from {url}")
download_file(f"https://wago.tools/db2/SpellItemEnchantment/csv?branch={branch}", f"/tmp/SpellItemEnchantment.csv")
class SpellEnchant:
def __init__(self, id, description):
self.enchantID = int(id)
self.description = description
def loadEnchants() -> Mapping[int, SpellEnchant]:
enchants = {}
with open('/tmp/SpellItemEnchantment.csv', newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
enchant = SpellEnchant(
row['ID'],
row['Name_lang']
)
enchants[int(row['ID'])] = enchant
return enchants
def loadDB() -> Set[int]:
with open(input_db_path) as dbfile:
dbjson = json.load(dbfile)
enchants = []
for enchant in dbjson['enchants']:
enchants.append(enchant['effectId'])
return sorted(enchants)
enchantDesc = loadEnchants()
enchantDB = loadDB()
output = {}
for enchant in enchantDB:
if not enchant in enchantDesc:
print (f"WARN: {enchant} not found in SpellItemEnchantment.")
continue
output[enchant] = enchantDesc[enchant].description
with open(output_file_path, 'w') as o:
json.dump(output, o)