-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
GTrecipe.py
170 lines (167 loc) · 9.86 KB
/
GTrecipe.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import requests
from bs4 import BeautifulSoup
def ItemRecipe(NameItem, Region = "en"):
try:
ItemFinder = requests.get(f"https://growtopia.fandom.com/"+Region+"/api/v1/SearchSuggestions/List?query="+NameItem).json()
try:
ItemPage = requests.get("https://growtopia.fandom.com/"+Region+"/"+"wiki/"+ItemFinder["items"][0]["title"])
try:
HTMLResult = BeautifulSoup(ItemPage.text, "html.parser")
require = []
Result = {}
def Insert(this,Recipe):
if this in Recipe.keys():
Recipe[this].append([])
for meh in item.select('td'):
meh = ((meh.get_text(' ',strip=True)).replace('"',"'"))
Recipe[this][1].append(meh.replace(u'\xa0', u''))
else:
Recipe[this] = [[]]
for meh in item.select('td'):
meh = ((meh.get_text(' ',strip=True)).replace('"',"'"))
Recipe[this][0].append(meh.replace(u'\xa0', u''))
def Insert2(this,Recipe):
if this in Recipe[meh].keys():
Recipe[meh][this].append([])
for the in mes.select('td'):
the = ((the.get_text(' ',strip=True)).replace('"',"'"))
Recipe[meh][this][1].append(the.replace(u'\xa0', u''))
else:
Recipe[meh][this] = [[]]
for the in mes.select('td'):
the = ((the.get_text(' ',strip=True)).replace('"',"'"))
Recipe[meh][this][0].append(the.replace(u'\xa0', u''))
def Title(itemish):
try:
ItemTitle = ((((itemish.find('span', class_= "mw-headline")).small).decompose()).get_text(strip=True)).replace(u'\xa0', u' ')
except:
ItemTitle = (itemish.find('span', class_= "mw-headline").get_text(strip=True)).replace(u'\xa0', u' ')
return ItemTitle
if Region == "id":
ind = HTMLResult.select_one(".tabber.wds-tabber")
if len(HTMLResult.select(".gtw-card")) == 1:
ws = 0
count = 0
Recipe = {}
for item in HTMLResult.select(".content"):
if item.select(".content") == []:
if not count in require:
Insert(((item.find('th')).text).strip(), Recipe)
ws += 1
else:
meh = ((item.find('th')).text).strip()
Recipe[meh] = {}
for mes in item.select(".content"):
Insert2(((mes.find('th')).text).strip(), Recipe)
ws += 1
require.append(ws)
count +=1
Result[Title(HTMLResult)] = Recipe
Result[Title(HTMLResult)]["Title"] = ItemFinder["items"][0]["title"]
else:
for itemish in ind.select(".wds-tab__content"):
ws = 0
count = 0
Recipe = {}
if itemish.select(".content") == []:
for item in HTMLResult.select(".content"):
if item.select(".content") == []:
if not count in require:
Insert(((item.find('th')).text).strip(), Recipe)
ws += 1
else:
meh = ((item.find('th')).text).strip()
Recipe[meh] = {}
for mes in item.select(".content"):
Insert2(((mes.find('th')).text).strip(), Recipe)
ws += 1
require.append(ws)
count +=1
Result[Title(itemish)] = Recipe
Result[Title(itemish)]["Title"] = ItemFinder["items"][0]["title"]
else:
for item in itemish.select(".content"):
if item.select(".content") == []:
if not count in require:
Insert(((item.find('th')).text).strip(), Recipe)
ws += 1
else:
meh = ((item.find('th')).text).strip()
Recipe[meh] = {}
for mes in item.select(".content"):
Insert2(((mes.find('th')).text).strip(), Recipe)
ws += 1
require.append(ws)
count +=1
Result[Title(itemish)] = Recipe
Result[Title(itemish)]["Title"] = ItemFinder["items"][0]["title"]
else:
if HTMLResult.select(".wds-tab__content") == []:
ws = 0
count = 0
Recipe = {}
for item in HTMLResult.select(".content"):
if item.select(".content") == []:
if not count in require:
Insert(((item.find('th')).text).strip(), Recipe)
ws += 1
else:
meh = ((item.find('th')).text).strip()
Recipe[meh] = {}
for mes in item.select(".content"):
Insert2(((mes.find('th')).text).strip(), Recipe)
ws += 1
require.append(ws)
count +=1
Result[Title(HTMLResult)] = Recipe
Result[Title(HTMLResult)]["Title"] = ItemFinder["items"][0]["title"]
else:
for itemish in HTMLResult.select(".wds-tab__content"):
ws = 0
count = 0
Recipe = {}
if itemish.select(".content") == []:
for item in HTMLResult.select(".content"):
if item.select(".content") == []:
if not count in require:
Insert(((item.find('th')).text).strip(), Recipe)
ws += 1
else:
meh = ((item.find('th')).text).strip()
Recipe[meh] = {}
for mes in item.select(".content"):
Insert2(((mes.find('th')).text).strip(), Recipe)
ws += 1
require.append(ws)
count +=1
Result[Title(itemish)] = Recipe
Result[Title(itemish)]["Title"] = ItemFinder["items"][0]["title"]
else:
for item in itemish.select(".content"):
if item.select(".content") == []:
if not count in require:
Insert(((item.find('th')).text).strip(), Recipe)
ws += 1
else:
meh = ((item.find('th')).text).strip()
Recipe[meh] = {}
for mes in item.select(".content"):
Insert2(((mes.find('th')).text).strip(), Recipe)
ws += 1
require.append(ws)
count +=1
Result[Title(itemish)] = Recipe
Result[Title(itemish)]["Title"] = ItemFinder["items"][0]["title"]
try:
return Result[ItemFinder["items"][0]["title"]]
except:
if NameItem in Result.keys():
return Result[NameItem]
else:
return Result
except:
return({"Error": "Sorry! I can't find "+NameItem+" in Growtopia Fandom "+Region+" Error Code 3"})
except IndexError:
return({"Error": "Sorry! I can't find "+NameItem+" in Growtopia Fandom "+Region+" Error Code 2"})
except:
return({"Error": "It looks like we can't reach fandom.com "+Region+"! Try again later. Error Code 1"})