diff options
author | dmonty2 <dmonty@sd73.bc.ca> | 2014-03-16 22:25:18 -0700 |
---|---|---|
committer | dmonty2 <dmonty@sd73.bc.ca> | 2014-03-16 22:25:18 -0700 |
commit | 5e5810800664a1e5698b6f6dd0de7b033c09014e (patch) | |
tree | 14cb629a0592f65316ced7bcfb82fa23a08d2600 /update_from_db2.py | |
parent | 039f49f408e58d5698daf64ecdd40b7af711b0d4 (diff) |
1.0
Diffstat (limited to 'update_from_db2.py')
-rwxr-xr-x | update_from_db2.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/update_from_db2.py b/update_from_db2.py new file mode 100755 index 0000000..0afe1c9 --- /dev/null +++ b/update_from_db2.py @@ -0,0 +1,45 @@ +#!/usr/bin/python3 +#from http.client import HTTPConnection +import json +import base64 +import requests + +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() + r = requests.get("http://"+str(server)+"/api/get.json.php?getlist&page="+str(page)+"&outformat=base64") + except StandardError: + print("Error", r.status) + exit(r.status) + data = r.text + 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() + i = i + 1 +addpage(1) +if pages > 1: + for p in range(pages-1): + addpage(p+2) +print("Skins have been updated. Please run ./generate_previews.sh") + |