-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoyalCommandsMaterial.py
73 lines (70 loc) · 2.96 KB
/
RoyalCommandsMaterial.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
import requests, re, csv, os
from bs4 import BeautifulSoup
file_name = "items.csv"
if os.path.exists(file_name):
os.remove(file_name) # bad but I lazy
def createAlias(material):
material_re = re.compile("^(.+)_(.+)")
if "LEGACY_" in material:
return None
alias = []
alias.append(material)
#alias.append(material.replace("_", "")) Unsure about this one
if "_SPAWN_EGG" in material:
material = material.replace("_SPAWN", "")
if material_re.search(material):
x = re.search("^(.+)_(.+)", material)
alias.append("{}:{}".format(x[2], x[1]))
if "_WOOD" in material:
if material_re.search(material):
x = re.search("^(.+)_(.+)", material)
alias.append("{}:{}".format(x[2], x[1]))
if "_LOG" in material:
if material_re.search(material):
x = re.search("^(.+)_(.+)", material)
alias.append("{}:{}".format(x[2], x[1]))
if "_PLANKS" in material:
if material_re.search(material):
x = re.search("^(.+)_(.+)", material)
alias.append("{}:{}".format(x[2], x[1]))
if "_DOOR" in material:
if material_re.search(material):
x = re.search("^(.+)_(.+)", material)
alias.append("{}:{}".format(x[2], x[1]))
if "_SLAB" in material:
if material_re.search(material):
x = re.search("^(.+)_(.+)", material)
alias.append("{}:{}".format(x[2], x[1]))
if "_STAIR" in material:
if material_re.search(material):
x = re.search("^(.+)_(.+)", material)
alias.append("{}:{}".format(x[2], x[1]))
if "REDSTONE_" in material:
if material_re.search(material):
x = re.search("^(.+)_(.+)", material)
alias.append("{}:{}".format(x[1], x[2]))
if "_ORE" in material:
if material_re.search(material):
x = re.search("^(.+)_(.+)", material)
alias.append("{}:{}".format(x[2], x[1]))
if "_WOOL" in material:
if material_re.search(material):
x = re.search("^(.+)_(.+)", material)
alias.append("{}:{}".format(x[2], x[1]))
if "_CARPET" in material:
if material_re.search(material):
x = re.search("^(.+)_(.+)", material)
alias.append("{}:{}".format(x[2], x[1]))
alias_string = ','.join(alias)
return alias_string.lower()
page = requests.get("https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html")
soup = BeautifulSoup(page.content, 'html.parser')
table = soup.find('section', class_='constants-summary')
for data in table.find_all('div', class_='col-first'):
for item in data.find_all('a'):
if(createAlias(item.text)):
row = [item.text, 0, '{}'.format(createAlias(item.text))]
with open('items.csv', 'a', encoding='UTF8', newline='', ) as f:
writer = csv.writer(f, quotechar="\"", quoting=csv.QUOTE_ALL)
# write the data
writer.writerow(row)