1
0
mirror of https://github.com/SmallJoker/minetest-u_skinsdb.git synced 2024-11-16 07:00:18 +01:00
minetest-u_skinsdb/update_from_db.py
SmallJoker dc44a8805f Update
2014-07-23 13:46:42 +02:00

58 lines
1.4 KiB
Python
Executable File

#!/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(s["name"] + '\n')
f.write(s["author"] + '\n')
f.write(s["license"])
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!")