-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_icons.py
39 lines (29 loc) · 1.04 KB
/
get_icons.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
from bs4 import BeautifulSoup
from requests import get
from PIL import Image
# To generate images you need to install these:
# pip install bs4
# pip install requests
# pip install pil
# Where to save pics?
path = "pics/[file].png"
# File name format
file_name = "[id]"
positions = {}
f = open("items.txt", "r")
for i in f:
t = i.split(": ")
positions[t[0]] = t[1].replace("\n", "")
soup = BeautifulSoup(get("https://minecraft-ids.grahamedgecombe.com/").text, "html.parser")
items = soup.find_all("tr", {"class": "row"})
li = {}
img = Image.open(get("https://minecraft-ids.grahamedgecombe.com/images/sprites/items-27.png", stream=True).raw)
for a in items:
pos = a.find("td", {"class": "row-icon"}).div["class"][1][6:]
desc = a.find("td", {"class": "row-desc"}).span.text
xy = positions[pos].split(" ")
x = abs(int(xy[0]))
y = abs(int(xy[1]))
final = path.replace("[file]", file_name.replace("[id]", a.td.text.replace(":", "_")).replace("[name]", desc))
img.crop((x, y, x + 32, y + 32)).save(final)
li[a.td.text] = 0