-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathutil.py
179 lines (158 loc) · 4.9 KB
/
util.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
171
172
173
174
175
176
177
178
179
import asyncio
# driver = webdriver.Chrome(executable_path=r"chromedriver.exe")
import json
from io import BytesIO
# import aiohttp
# import bs4
# import html5lib
# from bs4 import BeautifulSoup
# from selenium import webdriver
URL = "https://pokemondb.net/pokedex/all"
CDNURL = "https://assets.pokemon.com/assets/cms2/img/pokedex/detail/{}.png"
POKEDEX = "https://img.pokemondb.net/artwork/{}"
EVOLVE = "https://pokemondb.net/evolution/level"
SHINY = "https://pokemondb.net/pokedex/shiny"
# DOESNT DO MEGAS ETC.
async def main():
# # a = {"mega": [], "normal": [], "all": {}}
# driver.get(SHINY)
# await asyncio.sleep(10)
# soup = bs4.BeautifulSoup(driver.page_source, "html.parser")
# da = soup.find_all("div", {"class": "infocard-list infocard-list-pkmn-lg"})
# a = []
# for div in da:
# tags = div.find_all("div", {"class": "infocard"})
# for poke in tags:
# if len(poke.find_all("small")) == 2:
# num = int(poke.find("small").get_text().replace("#", ""))
# print(num)
# img = poke.find_all("img")
# if not img:
# print(img)
# img = img[1].attrs["src"]
# a.append([num, img])
# await write(a, "shiny")
# with open(f"pokecord/data/shiny.json", "r", encoding="utf-8") as f:
# a = json.load(f)
print(2)
with open(f"pokecord/data/pokedex.json", "r", encoding="utf-8") as f:
p = json.load(f)
with open(f"pokecord/data/legendary.json", "r", encoding="utf-8") as f:
l = json.load(f)
with open(f"pokecord/data/mythical.json", "r", encoding="utf-8") as f:
m = json.load(f)
data = p + l + m
a = []
MEGAS = [
3,
6,
9,
64,
94,
115,
127,
130,
142,
150,
181,
212,
214,
229,
248,
257,
282,
303,
306,
308,
310,
354,
359,
380,
381,
445,
448,
460,
15,
18,
80,
208,
254,
302,
319,
323,
334,
362,
373,
376,
384,
428,
475,
531,
719,
]
for pokemon in data:
if pokemon["id"] in MEGAS:
pokemon["variant"] = "Mega"
for stat in pokemon["stats"]:
pokemon["stats"][stat] += 50
pokemon["spawnchance"] = 0.001
pokemon["alias"] = f"Mega {pokemon['name']['english']}"
a.append(pokemon)
await write(a, "megas")
async def get_img():
session = aiohttp.ClientSession()
with open(f"pokecord/data/pokedex.json", "r", encoding="utf-8") as f:
data = json.load(f)
for pokemon in data:
img = await session.get(
f"https://assets.pokemon.com/assets/cms2/img/pokedex/detail/{str(pokemon['id']).zfill(3)}.png"
)
name = f"pokecord/data/pokemon/{pokemon['name']['english']}.png"
with open(name, "wb") as f:
f.write(BytesIO(await img.read()).getbuffer())
with open(f"pokecord/data/shiny.json", "r", encoding="utf-8") as f:
data = json.load(f)
for pokemon in data:
img = await session.get(pokemon["url"])
name = f"pokecord/data/pokemon/{pokemon['alias']}.png"
with open(name, "wb") as f:
f.write(BytesIO(await img.read()).getbuffer())
await session.close()
async def evolve():
a = {}
driver.get(EVOLVE)
BeautifulSoup(driver.page_source, "html5lib")
await asyncio.sleep(3)
soup = bs4.BeautifulSoup(driver.page_source, "html.parser")
table = soup.find("table", {"id": "evolution"})
evolves = table.find_all("tr")
for tag in evolves[1:]:
pokes = tag.find_all("span", {"class": "infocard-cell-data"})
lvl = tag.find("td", {"class": "cell-num"})
if lvl is None:
break
names = []
for pokemon in pokes:
small = pokemon.find("small", {"class": "text-muted"})
if small is None:
small = pokemon.find("a")
names.append(small.get_text())
a[names[0]] = {"evolution": names[1], "level": lvl.get_text()}
await write(a, "evolve")
async def write(lst, name):
with open(f"pokecord/data/{name}.json", "w") as f:
f.write(json.dumps(lst, indent=1))
def spawn_rate():
with open(f"pokecord/data/pokedex.json", "r", encoding="utf-8") as f:
data = json.load(f)
stats = []
for pokemon in data:
total = 0
for stat in pokemon["stats"]:
total += pokemon["stats"][stat]
stats.append(800 - total)
pokemon["spawnchance"] = (800 - total) / 800
with open(f"pokecord/data/pokedex.json", "w") as f:
f.write(json.dumps(data))
loop = asyncio.get_event_loop()
loop.run_until_complete(main())