forked from yashrajbharti/Pokemon-Image-Downloader-Upgrade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpokemon.py
49 lines (38 loc) · 1.58 KB
/
pokemon.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
# one can update to the latest dex by running this python script
import requests
import json
from pathlib import Path
from bs4 import BeautifulSoup
URL = "https://pokemondb.net/pokedex/national"
page = requests.get(URL)
soup = BeautifulSoup(page.content, "html.parser")
pokemonData = {}
results = soup.findAll(class_="infocard")
for result in results:
dexNumber = result.find("small")
pokemonName = result.find("a", class_="ent-name")
pokemonData[dexNumber.text[1:]
] = pokemonName.text.lower().replace("\u00e9", "e").replace("\u2640", "-f").replace("\u2642", "-m")
pokemonData[pokemonName.text.lower().replace("\u00e9", "e").replace("\u2640", "-f").replace("\u2642", "-m")
] = dexNumber.text[1:]
jsonData = json.dumps(pokemonData)
with open('./pokedexdata.json', 'w') as f:
f.write(jsonData)
imageData = {}
images = Path("./[HOME] Pokémon Renders/Shiny").glob("*.png")
for image in images:
pokedexNumber = (str(image).split("/")[2][13:17])
pokemonImage = str(image)
imageData[pokemonImage] = pokedexNumber
jsonImageData = json.dumps(imageData)
with open('./Images/shiny.json', 'w') as y:
y.write(jsonImageData)
imageDataNormal = {}
imagesNormal = Path("./[HOME] Pokémon Renders/Normal").glob("*.png")
for imageNormal in imagesNormal:
pokedexNumberNormal = (str(imageNormal).split("/")[2][13:17])
pokemonImageNormal = str(imageNormal)
imageDataNormal[pokemonImageNormal] = pokedexNumberNormal
jsonImageNormalData = json.dumps(imageDataNormal)
with open('./Images/normal.json', 'w') as z:
z.write(jsonImageNormalData)