This is the first time I have programmed something that I will actually personally use, so I am happy about that. I tried to write good code whilst applying functional programming concepts. So no state, and a concise function.
I know that when making the lists it pulls information from the JSON that doesn't get used later in the program. The data will be used once I get continue to develop the program further.
At the end there is a dictionary containing hero ID keys and name values. I cut out most of it to minimize the length of this post.
import json
import requests
def parsestats(herodata):
return [(hero['heroId'],
hero['pickBan']['pick']['matchCount']/ # Divide by next line
herodata['matchPickCount']*1000,
hero['pickBan']['ban']['matchCount']/ # Divide by next line
herodata['matchBanCount']*1000,
hero['pickBan']['pick']['wins']*100,
hero['pickBan']['ban']['wins']*100,
hero['pickBan']['pickLastWeek']['matchCount']/ # Divide by next line
herodata['matchLastWeekPickCount']*1000,
hero['pickBan']['banLastWeek']['matchCount']/ # Divide by next line
herodata['matchLastWeekBanCount']*1000,
hero['pickBan']['pickLastWeek']['wins']*100,
hero['pickBan']['banLastWeek']['wins']*100)
for hero in herodata['heroes']]
print(f"{'Hero,':<20}{'Value':>7}")
for hero in sorted(
[(uni[0], imm[1]*((uni[3] if uni[3] > imm[3] else imm[3])-50))
for uni, imm in zip(
sorted(parsestats(json.loads(requests.get(
'https://api.stratz.com/api/v1/Hero/directory/simple').text))),
sorted(parsestats(json.loads(requests.get(
'https://api.stratz.com/api/v1/Hero/directory/simple?rank=8').text))))
],
key=lambda tup: tup[1], reverse = True):
print("{:<20}{:>7.2f}".format({1: 'Anti-Mage', 2: 'Axe', 3: 'Bane', 4: 'Bloodseeker', 5: 'Crystal Maiden', 6: 'Drow Ranger', 7: 'Earthshaker', 8: 'Juggernaut', 9: 'Mirana', 10: 'Morphling', 11: 'Shadow Fiend', 12: 'Phantom Lancer', 13: 'Puck', 14: 'Pudge', 15: 'Razor', 16: 'Sand King', 17: 'Storm Spirit', 18: 'Sven', 19: 'Tiny', 20: 'Vengeful Spirit', 21: 'Windranger', 22: 'Zeus', 23: 'Kunkka', 25: 'Lina', 26: 'Lion', 27: 'Shadow Shaman', 28: 'Slardar', 29: 'Tidehunter', 30: 'Witch Doctor', 31: 'Lich', 32: 'Riki', 33: 'Enigma', 34: 'Tinker', 35: 'Sniper', 36: 'Necrophos', 37: 'Warlock', 38: 'Beastmaster',39: 'Queen of Pain', 40: 'Venomancer', 41: 'Faceless Void', 42: 'Wraith King', 43: 'Death Prophet', 44: 'Phantom Assassin', 45: 'Pugna', 46: 'Templar Assassin', 47: 'Viper', 48: 'Luna', 49: 'Dragon Knight', 50: 'Dazzle', 51: 'Clockwerk', 52: 'Leshrac', 53: 'Nature\'s Prophet', 54: 'Lifestealer', 55: 'Dark Seer', 56: 'Clinkz', 57: 'Omniknight', 58: 'Enchantress', 59: 'Huskar', 60: 'Night Stalker', 61: 'Broodmother', 62: 'Bounty Hunter', 63: 'Weaver', 64: 'Jakiro', 65: 'Batrider', 66: 'Chen', 67: 'Spectre', 68: 'Ancient Apparition', 69: 'Doom', 70: 'Ursa', 71: 'Spirit Breaker', 72: 'Gyrocopter', 73: 'Alchemist', 74: 'Invoker', 75: 'Silencer', 76: 'Outworld Devourer', 77: 'Lycan', 78: 'Brewmaster', 79: 'Shadow Demon', 80: 'Lone Druid', 81: 'Chaos Knight', 82: 'Meepo', 83: 'Treant Protector', 84: 'Ogre Magi', 85: 'Undying', 86: 'Rubick', 87: 'Disruptor', 88: 'Nyx Assassin', 89: 'Naga Siren', 90: 'Keeper of the Light', 91: 'Io', 92: 'Visage', 93: 'Slark', 94: 'Medusa', 95: 'Troll Warlord', 96: 'Centaur Warrunner', 97: 'Magnus', 98: 'Timbersaw', 99: 'Bristleback', 100: 'Tusk', 101: 'Skywrath Mage', 102: 'Abaddon', 103: 'Elder Titan', 104: 'Legion Commander', 105: 'Techies', 106: 'Ember Spirit', 107: 'Earth Spirit', 108: 'Underlord', 109: 'Terrorblade', 110: 'Phoenix', 111: 'Oracle', 112: 'Winter Wyvern', 113: 'Arc Warden', 114: 'Monkey King', 119: 'Dark Willow', 120: 'Pangolier',
121: 'Grimstroke', 129: 'Mars'}[hero[0]], hero[1]))