def test_hero_arg(self): hero = entities.Hero(1) hero_id = 1 res1 = self.get_match_history(account_id = '76561198088874284', hero = hero) res2 = self.get_match_history(account_id = '76561198088874284', hero_id = hero_id) self.assertEqual(res1, res2, "get_match_history(hero = {0}) should be the same as get_match_history(hero_id = {1})".format(hero, hero_id))
def test_match_content(self): match_id = '4176987886' res = self.get_match_details(match_id) q = res['players_minimal'][0]['hero'] a = entities.Hero(35) self.assertEqual(q, a, 'get_match_details(\'{0}\')[\'players_minimal\'][0][\'hero\'] is {1}'.format(match_id, a)) q = res['players'][6].all_items()[0]['item_name'] a = 'item_tango' self.assertEqual(q, a, 'get_match_details(\'{0}\')[\'players\'][6].all_items()[0][\'item_name\'] is {1}'.format(match_id, a)) q = res['dire_buildings']['tower_status'] a = 2047 self.assertEqual(q, a, 'get_match_details(\'{0}\')[\'dire_buildings\'][\'tower_status\'] is {1}'.format(match_id, a))
from d2api.src import entities # Hero/Item/Ability information is available without having to specify a key print(entities.Hero(67)['hero_name']) print(entities.Item(208)['item_aliases']) print(entities.Ability(6697)['ability_name']) # Use steam32/steam64 IDs interchangeably steam_account = entities.SteamAccount(1020002) print(steam_account['id32'], steam_account['id64'])
import d2api from d2api.src import entities api = d2api.APIWrapper() # fetch latest matches match_history = api.get_match_history() # get frequency of heroes played in the latest 100 games heroes = {} for match in match_history['matches']: for player in match['players']: hero_id = player['hero']['hero_id'] if not hero_id in heroes: heroes[hero_id] = 0 heroes[hero_id] += 1 # print hero frequency by name for hero_id, freq in heroes.items(): print(entities.Hero(hero_id)['hero_name'], freq)
def test_hero_bool(self): hero1 = entities.Hero(None) hero2 = entities.Hero(2) self.assertTrue(not hero1, "not {0} should be True".format(hero1)) self.assertFalse(not hero2, "not {0} should be False".format(hero2))
def test_hero_repr(self): hero_repr = repr(entities.Hero(1)) hero_match_str = "Hero(hero_id = 1)" self.assertEqual( hero_repr, hero_match_str, "repr(entities.Hero(1)) should be {0}".format(hero_match_str))