def get_collection(collection_url): response = _retry_session().get(onomancer_url + collection_hook + urllib.parse.quote(collection_url)) if response.status_code == 200: for player in response.json()['lineup'] + response.json()['rotation']: db.cache_stats(player['name'], json.dumps(player)) return json.dumps(response.json())
def get_stats(name): player = db.get_stats(name) if player is not None: return player #returns json_string #yell at onomancer if not in cache or too old response = _retry_session().get(onomancer_url + name_stats_hook + urllib.parse.quote_plus(name)) if response.status_code == 200: stats = json.dumps(response.json()) db.cache_stats(name, stats) return stats
def get_names(limit=20, threshold=1): """ Get `limit` random players that have at least `threshold` upvotes. Returns dictionary keyed by player name of stats. """ response = _retry_session().get( onomancer_url + names_hook, params={ 'limit': limit, 'threshold': threshold, 'with_stats': 1, 'random': 1, }, ) response.raise_for_status() res = {} for stats in response.json(): name = stats['name'] db.cache_stats(name, json.dumps(stats)) res[name] = stats return res