Exemple #1
0
def main(args):
  player_id = args[1] if len(args) > 1 else yasp_util.get_player_id()
  req = requests.get("http://yasp.co/players/{0}?json=1".format(player_id))
  json = req.json()
  sorted_heroes = sorted(json['aggData']['heroes'].values(), key=score)
  sorted_heroes.reverse()

  hero_data = yasp_util.get_hero_data()

  for data in sorted_heroes[:10]:
    wins = data['win']
    games = data['games']
    losses = games - wins
    hero_info = hero_data[int(data['hero_id'])]
    print "{0}: {1}W {2}L {3:.2%}".format(hero_info['localized_name'], wins, losses, float(wins)/games)
def main(args):
  player_id = yasp_util.get_player_id()
  hero_id = yasp_util.get_hero_id()

  req = requests.get("http://yasp.co/players/{0}/matches?json=1".format(player_id))
  json = req.json()

  def valid(match):
    return ('parse_status' in match and
           match['parse_status'] == 2 and
           str(match['players'][0]['hero_id']) == hero_id)

  valid_matches = filter(valid, json['data'])
  if not os.path.exists('matches'):
    os.makedirs('matches')
  for match in valid_matches:
    match_id = match['match_id']
    file_name = 'matches/{0}.json'.format(match_id)
    if not os.path.isfile(file_name):
      print 'grabbing {0}'.format(match_id)
      call(['curl', '-o', file_name, 'http://yasp.co/matches/{0}?json=1'.format(match_id)])