-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenFile.py
65 lines (64 loc) · 2.24 KB
/
genFile.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
from lib2to3.pgen2.literals import simple_escapes
import json
from bs4 import BeautifulSoup
import requests
import os
data = {"item": [
]}
items = os.listdir('./Old items')
for i, scuffedName in enumerate(items):
item = scuffedName[:scuffedName.find("_item")]
itemName = item.replace('_',' ').replace('%27','\'').replace('%28','(').replace('%29',')')
url = f"https://leagueoflegends.fandom.com/wiki/{item}"
result = requests.get(url)
doc = BeautifulSoup(result.text, 'html.parser')
passiveChild = doc.find_all(text="Passive")
statsChild = doc.find_all(text="Stats")
consumeChild = doc.find_all(text="Consume")
activeChild = doc.find_all(text="Active")
try:
passive = passiveChild[0].parent.parent.div.div.get_text()
except:
passive = "undefined"
try:
stats = statsChild[0].parent.parent.find_all("div",{"data-source":True})
for j, stat in enumerate(stats):
stats[j] = stat.text.replace('\n',"")
except:
stats = []
try:
consume = consumeChild[0].parent.parent.find("div").text.replace('\n',"")
except:
consume = "undefined"
try:
active = activeChild[0].parent.parent.find("div").text.replace('\n',"")
except:
active = "undefined"
#print(passive)
#print(stats)
#print(consume)
alternativeNames = []
if "'s" in itemName:
alternativeNames.append(itemName.replace("'s",""))
alternativeNames.append(itemName.replace("'",""))
if " the" in itemName:
alternativeNames.append(itemName.replace(" the",""))
if " the" in itemName:
alternativeNames.append(itemName.replace(" the",""))
if "." in itemName:
alternativeNames.append(itemName.replace(".",""))
fullItem = {
'id': i,
'name': itemName,
'alternativeName': alternativeNames,
'active': active,
'passive': passive,
'stats': stats,
'consume': consume,
'file': scuffedName
}
data['item'].append(fullItem)
if passive=="undefined" and len(stats)==0 and consume=="undefined":
print(fullItem)
with open('items.json', 'w', encoding='utf8') as jsonFile:
json.dump(data, jsonFile, ensure_ascii=False, indent=2)