summaryrefslogtreecommitdiff
path: root/update_from_db_hacky.py
blob: 1ae3280538c8d7612417b26487f6d73b8f025521 (plain)
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
#!/usr/bin/python3
from http.client import HTTPConnection
import json
import base64

server = "minetest.fensta.bplaced.net"
skinsdir = "u_skins/textures/"
metadir = "u_skins/meta/"
i = 1
pages = 0

c = HTTPConnection(server)
def addpage(page):
	global i, pages
	print( "Page: "+str(page))
	try:
		c.request("GET","/api/get.json.php?getlist&page="+str(page)+"&outformat=base64")
		r = c.getresponse()
	except StandardError:
		c.request("GET","/api/get.json.php?getlist&page="+str(page)+"&outformat=base64")
		r = c.getresponse()
		if r.status != 200:
			print("Error", r.status)
			exit(r.status)
	data = r.read().decode()
	l = json.loads(data)
	if not l["success"]:
		print("Success != True")
		exit(1)
	pages = int(l["pages"])
	for s in l["skins"]:
		f = open(skinsdir+"character_"+str(i)+".png",'wb')
		f.write(base64.b64decode(s["img"]))
		f.close()
		f = open(metadir+"character_"+str(i)+".txt",'w')
		f.write('name = "'+s["name"]+'",\n')
		f.write('author = "'+s["author"]+'",\n')
		f.write('comment = "'+s["license"]+'",\n')
		f.close()
		try:
			c.request("GET","/skins/1/"+str(s["id"])+".png")
			r = c.getresponse()
		except StandardError:
			c.request("GET","/skins/1/"+str(s["id"])+".png")
			r = c.getresponse()
			if r.status != 200:
				print("Error", r.status)
				exit(r.status)
		data = r.read()
		f = open(skinsdir+"character_"+str(i)+"_preview.png",'wb')
		f.write(data)
		f.close()
		i = i + 1
addpage(1)
if pages > 1:
	for p in range(pages-1):
		addpage(p+2)
print("Skins have been updated!")