コード例 #1
0
ファイル: conftest.py プロジェクト: CHuKeR/ggscore
def add_start_team(start_db):
    test_team1 = Teams(id=1, name='NaVi', tag='NaVi')
    test_team2 = Teams(id=2, name='Virtus Pro', tag='VP')
    test_team3 = Teams(id=3, name='Team Spirit', tag='Spirit')
    test_team4 = Teams(id=4, name='Evil Genius', tag='EG')
    session.add(test_team1)
    session.add(test_team2)
    session.add(test_team3)
    session.add(test_team4)
    session.commit()
コード例 #2
0
ファイル: conftest.py プロジェクト: CHuKeR/ggscore
def start_matches(start_db):
    for seria in dota_start_matches:
        seria_ = Series(id=seria['seria_id'],
                        team1_name=seria['team1_name'],
                        team2_name=seria['team2_name'],
                        tournament_name=seria['tour_title'],
                        series_url=seria['match_link'],
                        date=seria['date'],
                        finished=False)
        session.add(seria_)
    session.commit()
コード例 #3
0
ファイル: worker.py プロジェクト: CHuKeR/ggscore
def update_finished_dota_matches():
    dota_parser = DotaParser()
    logger.info('Start update finished matches')
    matches = dota_parser.parse_finished_matches()
    for match in matches:
        seria = session.query(Series).filter(
            Series.id == match['seria_id']).first()
        if seria is not None:
            seria.score = match['result']
            seria.finished = True
            try:
                session.commit()
            except Exception as exc:
                logger.error(exc)
                session.rollback()
        else:
            logger.error(f'Match with {match["seria_id"]} not in database!')
コード例 #4
0
ファイル: worker.py プロジェクト: CHuKeR/ggscore
def update_future_dota_matches():
    updated_matches = []
    dota_parser = DotaParser()
    logger.info('Start updating future matches')
    matches = dota_parser.parse_future_matches()
    teams = Teams.get_all_teams_tags()
    for match in matches:
        updated = False
        if match['team1_name'] in teams or match['team2_name'] in teams:
            seria = session.query(Series).filter(
                Series.id == match['seria_id']).first()
            if seria is None:
                seria = Series(id=match['seria_id'],
                               team1_name=match['team1_name'],
                               team2_name=match['team2_name'],
                               tournament_name=match['tour_title'],
                               series_url=match['match_link'],
                               date=match['date'],
                               finished=False)

                session.add(seria)
            else:
                if match['date'] is not None and seria.date != match['date']:
                    seria.date = match['date']
                    updated = True
                if match['team1_name'] != seria.team1_name:
                    seria.team1_name = match['team1_name']
                    updated = True
                if match['team2_name'] != seria.team2_name:
                    seria.team2_name = match['team2_name']
                    updated = True
            if updated:
                updated_matches.append(seria)
            try:
                session.commit()
            except Exception as exc:
                logger.error(exc)
                session.rollback()
    return updated_matches
コード例 #5
0
 def delete_finished_matches(cls) -> None:
     session.query(cls).filter(cls.finished == True).delete(
         synchronize_session='fetch')
     session.commit()
コード例 #6
0
def delete_user(user_id: int):
    user = session.query(Users).filter(Users.id == user_id).first()
    session.delete(user)
    session.commit()
コード例 #7
0
def delete_team(message: str, user_id: int):
    team_id = int(message.split('_')[-1])
    user = session.query(Users).filter(Users.id == user_id).first()
    team = session.query(Teams).filter(Teams.id == team_id).first()
    user.teams.remove(team)
    session.commit()
コード例 #8
0
def add_user(user_id: int):
    user = session.query(Users).filter(Users.id == user_id).first()
    if user is None:
        session.add(Users(id=user_id))
        session.commit()
コード例 #9
0
ファイル: conftest.py プロジェクト: CHuKeR/ggscore
def add_teams_to_user(add_start_user, add_start_team):
    user = session.query(Users).first()
    teams = session.query(Teams).all()
    user.teams.append(teams[0])
    user.teams.append(teams[1])
    session.commit()
コード例 #10
0
ファイル: conftest.py プロジェクト: CHuKeR/ggscore
def add_start_user(start_db):
    test_user = Users(id=1)
    session.add(test_user)
    session.commit()