Beispiel #1
0
def add_match(match_id):
    """Queries a match from the Steam API and adds it to the database.
    Returns True if it succeeds or if match already exists, or False if it fails.
    """
    match = api.get_match_details(match_id)["result"]

    if "error" in match:
        return False

    try:
        new_match = Match.create(**match)
    except IntegrityError:
        return True
    except PyDotaError:
        return False

    player_list = [dict(match_id=new_match.match_id, **player) for player in match["players"]]

    with db.atomic():
        MatchPlayer.insert_many(player_list).execute()

    return True