def update_match_details(key, from_cache=True): match = db.get(key) or {} url = match["url"] if not url: return db.set(key, merge(match, match_detail(url)))
def update_player(key, from_cache=True): player = db.get(key) or {} url = player["url"] if not url: return player = merge(player, player_detail(url, from_cache=from_cache)) log.track_lacked(key, url, player) db.set(key, player)
def request_html(url, from_cache=True): html = db.get(url) if not html or not from_cache: log.debug("Request {}".format(url)) html = get_html(get_ajax_url(url)).get(blocking=True) db.set(url, html) return html
def remove_server(self, guild_id: int): raw_dict = db.get(self.DB_KEY) if raw_dict is not None: dictionary = get_dict(raw_dict) try: dictionary.pop(str(guild_id)) db.set(self.DB_KEY, json.dumps(dictionary)) except KeyError: pass
def set_value_for_server(self, guild_id, value): raw_dict = db.get(self.DB_KEY) if raw_dict is None: dictionary = {} else: dictionary = get_dict(raw_dict) dictionary[str(guild_id)] = value db.set(self.DB_KEY, json.dumps(dictionary))
def update_tournament_details(key, from_cache=True): tournament = db.get(key) or {} url = tournament["url"] if not url: return db.set( key, merge(tournament, tournament_detail(tournament["url"], from_cache=from_cache)), )
def update_matches_per_tournament_details(key, from_cache=True): tournament = db.get(key) url = tournament["url"] if not url: return matches = matches_list_per_tournament(url, from_cache=from_cache) for item in matches: item = dict( item, tournament_year=tournament["year"], tournament_slug=tournament["slug"], tournament_code=tournament["code"], ) match_key = build_match_key(item) merged_item = merge(db.get(match_key) or {}, item) log.track_lacked(key, url, merged_item) db.set(match_key, merged_item) player = merged_item["winner"] if player.get("url"): player_key = build_player_key(player["slug"], player["code"]) db.set(player_key, player) else: log.warning(f"Player without link, {url} {player}") player = merged_item["looser"] if player.get("url"): player_key = build_player_key(player["slug"], player["code"]) db.set(player_key, player) else: log.warning(f"Player without link, {url} {player}")
def update_tournaments(tournaments): for tournament in tournaments: key = build_tournament_key(tournament["year"], tournament["slug"], tournament["code"]) db.set(key, merge(db.get(key) or {}, tournament))