Skip to content

Instantly share code, notes, and snippets.

@johnp
Created May 5, 2012 18:18
Show Gist options
  • Save johnp/2604510 to your computer and use it in GitHub Desktop.
Save johnp/2604510 to your computer and use it in GitHub Desktop.
WoT-XVM iconLoader.py
# Python version 3.2
import sys;
import json;
import urllib.request;
"""
Change URLs according to server region.
Import by "import iconLoader from iconLoader" in python shell
Execute e.g. iconLoader("WG");
-> Downloads 24x24 icon and adds formatted config line to clanlist.txt
"""
def iconLoader(clanName):
if clanName is "":
sys.exit(-1);
req = urllib.request.Request("http://worldoftanks.eu/community/clans/?type=table&offset=0&limit=100&search="+clanName+"&echo=2&id=clans_index", headers = {'Content-Type': 'application/json'});
req.add_header('Accept-Encoding', 'paco');
req.add_header('Connection', 'close');
req.add_header('X-Requested-With', 'XMLHttpRequest');
opener = urllib.request.build_opener();
opener.addheaders = [('Accept', 'application/json, */*; q=0.01'),('Accept-Encoding', 'paco'), ('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7')];
f = opener.open(req);
datay = str(f.read()).rstrip("'").lstrip("b'");
datay = datay.replace(r'\x', r'\u00');
data = json.loads(datay);
for clan in data['request_data']['items']:
if clan['abbreviation'] == clanName:
clanID = str(clan['id']);
break;
if clanID is "":
sys.exit(-2);
pngName = clanName.lower()+".png";
with open(pngName, 'wb') as file:
req = urllib.request.Request("http://worldoftanks.eu/dcont/clans/emblems/"+clanID+"/emblem_24x24.png");
opener = urllib.request.build_opener();
f = opener.open(req);
file.write(f.read());
with open("clanlist.txt", 'a') as clanlist:
clanlist.write('{ clan: "['+clanName+']", icon: "'+pngName+'" },\n');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment