Create a gist now

Instantly share code, notes, and snippets.

@Lanjelin /armory.py Secret
Last active Apr 18, 2017

What would you like to do?
WoW Armory
# -*- coding: utf-8 -*-
import urllib2, json
from multiprocessing.dummy import Pool as ThreadPool
from chars import chars
from charInfo import *
from createImg import *
from fetchChar import *
# Make the Pool of workers
pool = ThreadPool(int(len(chars)/3))
print "Workers: " + str(int(len(chars)/3))
def grabChars(chars):
return fetchChar(chars[0],chars[1],chars[2])
results = pool.map(grabChars, chars)
pool.close()
pool.join()
level = 0
num = 0
miss = 0
for x in range(0, int(len(results))):
if results[x] == "404":
miss += 1
else:
level += int(results[x][1])
num += 1
print "No. chars: " + str(num)
print "Avg level: " + str(level/num)
print "Tot level: " + str(level)
print ""
print "Chars 404: " + str(miss)
print ""
cf, cl, cr, cc, ct = [],[],[],[],[]
for char in sorted(results, key=lambda stuff: stuff[1], reverse=True):
if char == "404":
continue
else:
c_name, c_level, c_gender, c_race, c_class, c_spec, c_realm = char #Splitting items returned
cf.append(int(getNumFaction(c_race)))
cl.append(str(c_level))
cr.append(str(c_race) + "_" + str(c_gender))
cc.append(str(c_class))
if isinstance(c_spec,(int,long)):
ct.append(str(c_class) + "_" + str(c_spec))
else:
ct.append("0")
c_faction, c_gender, c_race, c_spec, c_class = getCharInfo(c_gender,c_race,c_class,c_spec) #Getting string values
print c_name.ljust(10, " ") + "\t" + str(c_level) + "\t" + c_faction.ljust(8, " ") + "\t" + c_gender + "\t" + c_race.ljust(10, " ") + "\t" + c_spec.ljust(13, " ") + "\t" + c_class
img = createImg(cf, cl, cr, cc, ct)
img.save('test.jpg')
# -*- coding: utf-8 -*-
#Translate numerical value to gender name of the character
def getGender(c_gender):
if (c_gender == 0):
return "Male"
elif (c_gender == 1):
return "Female"
#Translate numerical value to race name of the character
def getRace(c_race):
races = {
1:"Human",
2:"Orc",
3:"Dwarf",
4:"Night Elf",
5:"Undead",
6:"Tauren",
7:"Gnome",
8:"Troll",
9:"Goblin",
10:"Blood Elf",
11:"Draenei",
22:"Worgen",
24:"Pandaren", #Neutral
25:"Pandaren", #Alliance
26:"Pandaren" #Horde
}
if (races[c_race]):
return races[c_race]
#Translate numerical value to class name of the character
def getClass(c_class):
classes = {
1:"Warrior",
2:"Paladin",
3:"Hunter",
4:"Rogue",
5:"Priest",
6:"Death Knight",
7:"Shaman",
8:"Mage",
9:"Warlock",
10:"Monk",
11:"Druid",
12:"Demon Hunter"
}
if (classes[c_class]):
return classes[c_class]
#Translate numerical vale of class and spec into the name of spec of that character
def getSpec(c_class, c_spec):
specs = {
1:["Arms","Fury","Protection"],
2:["Holy","Protection","Retribution"],
3:["Beast Master","Marksmanship","Survival"],
4:["Assassination","Outlaw","Subtley"],
5:["Discipline","Holy","Shadow"],
6:["Blood","Frost","Unholy"],
7:["Elemental","Enhancement","Restoration"],
8:["Arcane","Fire","Frost"],
9:["Affliction","Demonology","Destruction"],
10:["Brewmaster","Mistweaver","Windwalker"],
11:["Balance","Feral","Guardian","Restoration"],
12:["Havoc","Vengeance"]
}
if (specs[c_class][c_spec]):
return specs[c_class][c_spec]
def getFaction(c_race):
ally = [1,3,4,7,11,22,25]
horde = [2,5,6,8,9,10,26]
if c_race in ally:
return "Alliance"
elif c_race in horde:
return "Horde"
else: #Should be num 24 aka Panda only
return "Neutral"
def getNumFaction(c_race):
ally = [1,3,4,7,11,22,25]
horde = [2,5,6,8,9,10,26]
if c_race in ally:
return 1
elif c_race in horde:
return 2
else:
return 0
def getCharInfo(in_gender, in_race, in_class, in_spec):
return getFaction(in_race), getGender(in_gender), getRace(in_race), getSpec(in_class, in_spec), getClass(in_class)
#c_faction, c_gender, c_race, c_spec, c_class = getCharInfo(1,1,9,1)
#print c_faction + c_gender + c_race + c_spec + c_class
#info = getCharInfo(1,1,9,1)
#print info[0]
# -*- coding: utf-8 -*-
chars = [
("Lanjelin","Stormreaver","EU"),
("Slemmingen","Stormreaver","EU"),
("Mutator","Stormreaver","EU"),
("Tengle","Stormreaver","EU"),
("Thil","Stormreaver","EU"),
("Verberatus","Stormreaver","EU"),
("Badingo","Stormreaver","EU"),
("Lillija","Stormreaver","EU"),
("Minch","Stormreaver","EU"),
("Thraag","Stormreaver","EU"),
("Zanglia","Stormreaver","EU"),
("Zefonith","Stormreaver","EU"),
("Abeo","Frostmane","EU"),
("Clones","Frostmane","EU"),
("Venath","Frostmane","EU"),
("Zefonith","Frostmane","EU"),
("Zèrg","Frostmane","EU"),
("Lanjelin","Frostmane","EU"),
("Minath","Frostmane","EU"),
("Insomnium","Frostmane","EU"),
("Ilil","Frostmane","EU"),
("Zodila","Frostmane","EU"),
("Zanglia","Frostmane","EU"),
("Flazago","Aszune","EU"),
("Wulver","Aszune","EU"),
("Knoplia","Aszune","EU"),
("Kemek","Aszune","EU"),
("Sulia","Aszune","EU"),
("Tigia","Aszune","EU"),
("Whoper","Aszune","EU"),
("Waldek","Aszune","EU"),
("Mythisio","Aszune","EU"),
("Comala","Aszune","EU"),
("Solab","Aszune","EU"),
("Heilageku","Grim Batol","EU"),
("Kalyps","Grim Batol","EU"),
("Cili","Grim Batol","EU"),
("Corali","Grim Batol","EU"),
("Kaliti","Grim Batol","EU"),
("Awry","Grim Batol","EU"),
("Daunakken","Grim Batol","EU"),
("Qant","Grim Batol","EU"),
("Minitaur","Grim Batol","EU"),
("Colossia","Grim Batol","EU"),
("Klandaia","Grim Batol","EU"),
("Zorkia","Defias Brotherhood","EU"),
("Invictu","Defias Brotherhood","EU"),
("Carlyps","Defias Brotherhood","EU"),
("Tilath","Defias Brotherhood","EU"),
("Dorgul","Defias Brotherhood","EU")
]
# -*- coding: utf-8 -*-
from PIL import Image
from PIL import ImageDraw
#from PIL import ImageFont
imloc = "./wow/"
def createImg(cf, cl, cr, cc, ct): #faction, level, race, class, talent
tot_w = int(len(cr)) * 18
tot_h = 72 #4 img height
new_im = Image.new('RGB', (tot_w, tot_h))
offset_x = 0
draw = ImageDraw.Draw(new_im)
#font = ImageFont.truetype("RobotoCondensed-Bold.ttf", 16) # throws error, missing lib
fcolors = {
0:"yellow",
1:"blue",
2:"red"
}
for cfac, clev, crace, cclass, ctalent in zip(cf, cl, cr, cc, ct):
draw.rectangle([(offset_x * 18, 0),(offset_x * 18 + 18, 18)], (fcolors[int(cfac)]), outline=None)
draw.text((offset_x * 18 + 9 - (len(clev)*3), 3),clev,(255,255,255))
new_im.paste(Image.open(imloc + "r_" + crace + ".jpg"), (offset_x * 18, 18))
new_im.paste(Image.open(imloc + "c_" + cclass + ".jpg"), (offset_x * 18, 36))
new_im.paste(Image.open(imloc + "t_" + ctalent + ".jpg"), (offset_x * 18, 54))
offset_x += 1
draw.line(((offset_x * 18)-1,0, (offset_x * 18)-1,tot_h), fill="black", width=1)
draw.line(((offset_x - 1) * 18,18, offset_x * 18,18), fill="black", width=1)
draw.line(((offset_x - 1) * 18,36, offset_x * 18,36), fill="black", width=1)
draw.line(((offset_x - 1) * 18,54, offset_x * 18,54), fill="black", width=1)
draw.line((0,0, 0,tot_h), fill="black", width=1)
draw.line((0,0, tot_w,0), fill="black", width=1)
draw.line((0,tot_h, tot_w,tot_h), fill="black", width=1)
draw.line((tot_w,0, tot_w,tot_h), fill="black", width=1)
return new_im
cfac = ["1","2","1",1]
clev = ["1","76","109", "12"]
crac = ["5_1","4_0","8_1", "2_1"]
ccla = ["4","7","11", "12"]
ctal = ["5_2","4_1","3_1","7_1"]
#createImg(cfac, clev, crac, ccla, ctal).save('test.jpg')
# -*- coding: utf-8 -*-
import os
from urllib2 import urlopen, URLError, HTTPError, build_opener
def Download(url, file):
name = file
try:
o = build_opener()
o.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20120101 Firefox/33.0')]
get = o.open(url)
with open(file, "wb") as file:
file.write(get.read())
file.close()
return os.path.basename(file.name) + " saved successfully."
except HTTPError, e:
return "HTTP Error: " + str(e.code) + " - " + name #url
except URLError, e:
return "URL Error: " + str(e.reason) + " - " + name #url
def Down(url):
file = url.split('/')[-1]
return Download(url, file)
#print downloadSimple("http://placehold.it/350x150")
# -*- coding: utf-8 -*-
import urllib2, json
apikey = "m7ec9xtrvn6p3fj8bpndt978um8m78g6"
def fetchChar(name, realm, loc):
if loc.upper() == "CN":
#Still not working though, see dev forum.
url = "https://api.battlenet.com.cn/wow/character/"+realm+"/"+name+"?fields=talents&locale=en_GB&apikey="+apikey
else:
url = "https://"+loc+".api.battle.net/wow/character/"+realm+"/"+name+"?fields=talents&locale=en_GB&apikey="+apikey
try:
response = urllib2.urlopen(url)
except:
print "Couldn't find "+name+" - "+realm+" - "+loc
return "404"
else:
data = json.load(response)
for item in data["talents"]:
if item["calcSpec"]:
try:
if item["selected"]:
talent = item["spec"]["order"]
except:
continue
return data['name'].encode("utf-8"), data['level'], data['gender'], data['race'], data['class'], talent, data['realm'].encode("utf-8")
#print fetchChar("Lanjelin","Stormreaver","EU")
# -*- coding: utf-8 -*-
from download import *
path = "./wow/"
print Download("http://wow.zamimg.com/images/wow/icons/small/class_warrior.jpg", path+"c_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/class_paladin.jpg", path+"c_2.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/class_hunter.jpg", path+"c_3.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/class_rogue.jpg", path+"c_4.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/class_priest.jpg", path+"c_5.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/class_deathknight.jpg", path+"c_6.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/class_shaman.jpg", path+"c_7.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/class_mage.jpg", path+"c_8.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/class_warlock.jpg", path+"c_9.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/class_monk.jpg", path+"c_10.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/class_druid.jpg", path+"c_11.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/class_demonhunter.jpg", path+"c_12.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_human_male.jpg", path+"r_1_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_human_female.jpg", path+"r_1_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_orc_male.jpg", path+"r_2_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_orc_female.jpg", path+"r_2_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_dwarf_male.jpg", path+"r_3_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_dwarf_female.jpg", path+"r_3_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_nightelf_male.jpg", path+"r_4_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_nightelf_female.jpg", path+"r_4_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_scourge_male.jpg", path+"r_5_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_scourge_female.jpg", path+"r_5_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_tauren_male.jpg", path+"r_6_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_tauren_female.jpg", path+"r_6_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_gnome_male.jpg", path+"r_7_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_gnome_female.jpg", path+"r_7_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_troll_male.jpg", path+"r_8_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_troll_female.jpg", path+"r_8_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_goblin_male.jpg", path+"r_9_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_goblin_female.jpg", path+"r_9_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_bloodelf_male.jpg", path+"r_10_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_bloodelf_female.jpg", path+"r_10_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_draenei_male.jpg", path+"r_11_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_draenei_female.jpg", path+"r_11_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_worgen_male.jpg", path+"r_22_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_worgen_female.jpg", path+"r_22_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_pandaren_male.jpg", path+"r_24_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_pandaren_female.jpg", path+"r_24_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_pandaren_male.jpg", path+"r_25_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_pandaren_female.jpg", path+"r_25_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_pandaren_male.jpg", path+"r_26_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/race_pandaren_female.jpg", path+"r_26_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/ability_warrior_savageblow.jpg", path+"t_1_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/ability_warrior_innerrage.jpg", path+"t_1_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/ability_warrior_defensivestance.jpg", path+"t_1_2.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_holy_holybolt.jpg", path+"t_2_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/ability_paladin_shieldofthetemplar.jpg", path+"t_2_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_holy_auraoflight.jpg", path+"t_2_2.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/ability_hunter_bestialdiscipline.jpg", path+"t_3_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/ability_hunter_focusedaim.jpg", path+"t_3_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/ability_hunter_camouflage.jpg", path+"t_3_2.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/ability_rogue_eviscerate.jpg", path+"t_4_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/ability_backstab.jpg", path+"t_4_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/ability_stealth.jpg", path+"t_4_2.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_holy_powerwordshield.jpg", path+"t_5_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_holy_guardianspirit.jpg", path+"t_5_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_shadow_shadowwordpain.jpg", path+"t_5_2.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_deathknight_bloodpresence.jpg", path+"t_6_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_deathknight_frostpresence.jpg", path+"t_6_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_deathknight_unholypresence.jpg", path+"t_6_2.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_nature_lightning.jpg", path+"t_7_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_nature_lightningshield.jpg", path+"t_7_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_nature_magicimmunity.jpg", path+"t_7_2.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_holy_magicalsentry.jpg", path+"t_8_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_fire_firebolt02.jpg", path+"t_8_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_frost_frostbolt02.jpg", path+"t_8_2.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_shadow_deathcoil.jpg", path+"t_9_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_shadow_metamorphosis.jpg", path+"t_9_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_shadow_rainoffire.jpg", path+"t_9_2.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/monk_stance_drunkenox.jpg", path+"t_10_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/monk_stance_wiseserpent.jpg", path+"t_10_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/monk_stance_whitetiger.jpg", path+"t_10_2.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_nature_starfall.jpg", path+"t_11_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/ability_druid_catform.jpg", path+"t_11_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/ability_racial_bearform.jpg", path+"t_11_2.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/spell_nature_healingtouch.jpg", path+"t_11_3.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/ability_demonhunter_specdps.jpg", path+"t_12_0.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/ability_demonhunter_spectank.jpg", path+"t_12_1.jpg")
print Download("http://wow.zamimg.com/images/wow/icons/small/inv_misc_questionmark.jpg", path+"t_0.jpg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment