Created
February 28, 2013 14:48
-
-
Save bartku/5057263 to your computer and use it in GitHub Desktop.
Print CW ready tanks owned by given clan. ./clan-cw-tanks.py ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
import grequests | |
import sys | |
from prettytable import PrettyTable | |
if len(sys.argv) != 2: | |
print("Missing clan ID") | |
sys.exit | |
clanID = int(sys.argv[1]) | |
clan = requests.get("http://worldoftanks.eu/community/clans/{}/api/1.1/?source_token=WG-WoT_Assistant-1.3.2".format(clanID)) | |
profilLink = "http://worldoftanks.eu/uc/accounts/{}/api/1.9/?source_token=WG-WoT_Assistant-1.3.2" | |
members = [profilLink.format(i['account_id']) for i in clan.json()['data']['members']] | |
reqs = (grequests.get(u) for u in members) | |
# {"T34_hvy": {"localized_name": "T34", "level": 8, "class": "heavyTank", "nation": "usa", "amount": 20}} | |
vehicleStats = {} | |
tankProperNames = { | |
'Ch19_121': '121', | |
'Object263': 'Object 263', | |
'Object268': 'Object 268', | |
'JagdPz_E100': 'JagdPz E-100', | |
'AMX_50Fosh_155': 'AMX-50 Foch (155)', | |
'Ch22_113': '113', | |
'GB13_FV215b': 'FV215b', | |
'T57_58': 'T57 HT', | |
'E50_Ausf_M': 'E-50M', | |
'GB70_FV4202_105': 'FV4202' | |
} | |
def correctNames(x): | |
return tankProperNames[x] | |
for item in grequests.imap(reqs, size=5): | |
if item.status_code == 200: | |
if item.json()['status'] == "ok" and item.json()['status_code'] == "NO_ERROR": | |
playerDataTanks = item.json()['data']['vehicles'] | |
for iTank in playerDataTanks: | |
if iTank['name'] in tankProperNames.keys(): | |
iTank['localized_name'] = correctNames(iTank['name']) | |
if vehicleStats.has_key(iTank['name']): | |
vehicleStats[iTank['name']]['amount'] += 1 | |
else: | |
vehicleStats[iTank['name']] = { 'localized_name': iTank['localized_name'], 'level': iTank['level'], 'nation': iTank['nation'], | |
'class': iTank['class'], 'amount': 1 } | |
table = PrettyTable(["Tank", "Level", "Class", "Amount"]) | |
table.sortby = "Level" | |
for k, v in vehicleStats.iteritems(): | |
if (v['class'] in ['AT-SPG', 'mediumTank', 'heavyTank'] and v['level'] == 10) or (v['class'] in ['SPG'] and v['level'] == 8): | |
table.add_row([v['localized_name'], v['level'], v['class'], v['amount']]) | |
print(table) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment