Exemplo n.º 1
0
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)))
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
    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))
Exemplo n.º 6
0
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)),
    )
Exemplo n.º 7
0
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}")
Exemplo n.º 8
0
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))