Esempio n. 1
0
def create_team_overview_message(team_id, team_name):
    dota_obj = dota(
        "alexa-skill-dota-analyst-final-project([email protected])")
    team_details = dota_obj.get_team_info(team_id, False)
    # Team location
    team_location = team_details['info']['location'][0]
    # Active players
    team_roster_one_ID = team_details['team_roster'][0]['ID']
    team_roster_two_ID = team_details['team_roster'][1]['ID']
    team_roster_three_ID = team_details['team_roster'][2]['ID']
    team_roster_four_ID = team_details['team_roster'][3]['ID']
    team_roster_five_ID = team_details['team_roster'][4]['ID']
    # Achievements List
    achievements_list = team_details['cups']
    achievements_length = len(achievements_list)
    # Format String
    message = f"Here is a short overview of {team_name}." \
        f" The team is currently located in {team_location}." \
        f" Their current active players are," \
        f" {team_roster_one_ID}," \
        f" {team_roster_two_ID}," \
        f" {team_roster_three_ID}," \
        f" {team_roster_four_ID}," \
        f" and {team_roster_five_ID}." \
        f" Overall the team has won a total of {achievements_length} major tournaments."
    return message
Esempio n. 2
0
def _create_new_players(players, path, create):
    # https://liquipedia.net/api-terms-of-use
    if players == []:
        return

    dota_obj = dota(
        "KB_Parser (https://github.com/Finger228/LiquiParser; [email protected]"
    )

    for player in players:
        player_idtf = get_idtf(player)
        if create == True:
            # time.sleep(5)
            player_info = dota_obj.get_player_info(player, True)
            player_info = _sort_player_data(player, player_info)
            with open('{}/players/{}.json'.format(path, player_idtf),
                      'w') as f:
                f.write(json.dumps(player_info, ensure_ascii=False))
            print("Json of {} created".format(player))
        else:
            with open('{}/players/{}.json'.format(path, player_idtf),
                      'r') as f:
                player_info = json.load(f)

        player_info = _player_json_to_scs(player, player_idtf, player_info)

        with open('{}/players/{}.scs'.format(path, player_idtf), 'w') as r:
            r.write(player_info)

        print("scs of {} created".format(player))
Esempio n. 3
0
def sync_game_current_league(context):
    dota_liquipedi = dota("appname")
    Session = sessionmaker(bind=engine)
    session = Session()
    games = dota_liquipedi.get_upcoming_and_ongoing_games()
    games_json = pyjson5.loads(str(games).replace("None", "'None'"))
    for game in games_json:
        if (session.query(Game).filter(
                Game.league_name == game["tournament"],
                Game.start_time == datetime.strptime(game["start_time"][0:-4],
                                                     "%B %d, %Y - %H:%M"),
        ).scalar()):
            logging.info("Такая игра существует")
        else:
            new_game = Game(
                game_id=None,
                league_id=get_league_id(game["tournament"]),
                league_name=game["tournament"],
                league_short_name=game["tournament_short_name"],
                team1=game["team1"],
                team2=game["team2"],
                game_format=game["format"],
                start_time=datetime.strptime(game["start_time"][0:-4],
                                             "%B %d, %Y - %H:%M"),
                twitch_channel=game["twitch_channel"],
            )
            session.add(new_game)
        session.commit()
Esempio n. 4
0
def sync_current_leagues(context):
    dota_liquipedi = dota("appname")
    try:
        tournaments = dota_liquipedi.get_tournaments()
        tournaments_json = pyjson5.loads(str(tournaments))
        add_leagues_to_database(tournaments_json)
    except AttributeError:
        logging.warning("Not found data in API")
Esempio n. 5
0
def create_team_roster_message(team_id, team_name):
    dota_obj = dota(
        "alexa-skill-dota-analyst-final-project([email protected])")
    team_details = dota_obj.get_team_info(team_id, False)

    team_roster_one_ID = team_details['team_roster'][0]['ID']
    team_roster_one_POS = team_details['team_roster'][0]['Position']
    if '/' in team_roster_one_POS:
        team_roster_one_POS = team_roster_one_POS.replace('/', " or ")
    if 'Position:' in team_roster_one_POS:
        team_roster_one_POS = team_roster_one_POS.replace('Position:', "")

    team_roster_two_ID = team_details['team_roster'][1]['ID']
    team_roster_two_POS = team_details['team_roster'][1]['Position']
    if '/' in team_roster_two_POS:
        team_roster_two_POS = team_roster_two_POS.replace('/', " or ")
    if 'Position:' in team_roster_two_POS:
        team_roster_two_POS = team_roster_two_POS.replace('Position:', "")

    team_roster_three_ID = team_details['team_roster'][2]['ID']
    team_roster_three_POS = team_details['team_roster'][2]['Position']
    if '/' in team_roster_three_POS:
        team_roster_three_POS = team_roster_three_POS.replace('/', " or ")
    if 'Position:' in team_roster_three_POS:
        team_roster_three_POS = team_roster_three_POS.replace('Position:', "")

    team_roster_four_ID = team_details['team_roster'][3]['ID']
    team_roster_four_POS = team_details['team_roster'][3]['Position']
    if '/' in team_roster_four_POS:
        team_roster_four_POS = team_roster_four_POS.replace('/', " or ")
    if 'Position:' in team_roster_four_POS:
        team_roster_four_POS = team_roster_four_POS.replace('Position:', "")

    team_roster_five_ID = team_details['team_roster'][4]['ID']
    team_roster_five_POS = team_details['team_roster'][4]['Position']
    if '/' in team_roster_five_POS:
        team_roster_five_POS = team_roster_five_POS.replace('/', " or ")
    if 'Position:' in team_roster_five_POS:
        team_roster_five_POS = team_roster_five_POS.replace('Position:', "")

    message = f"Here are the rosters for {team_name}. " \
            f" {team_roster_one_ID}, will be playing as position {team_roster_one_POS} (Hard-Carry)." \
            f" {team_roster_two_ID}, as position {team_roster_two_POS} (Semi-Carry)." \
            f" {team_roster_three_ID}, as position {team_roster_three_POS} (Offlaner)." \
            f" {team_roster_four_ID}, as position {team_roster_four_POS} (Roaming Support), and" \
            f" {team_roster_five_ID}, as position {team_roster_five_POS} (Hard Support)."
    return message
Esempio n. 6
0
def create_team_achievements_message(team_id, team_name):
    dota_obj = dota(
        "alexa-skill-dota-analyst-final-project([email protected])")
    team_details = dota_obj.get_team_info(team_id, False)
    achievements_list = team_details['cups']
    #re_achievements = re.sub('[^A-Za-z0-9]+', ' ', str(achievements_list))
    achievements_length = len(achievements_list)
    create_achievement_list = ""

    if achievements_length > 0:
        for i in range(achievements_length):
            create_achievement_list += f"{i+1}, {achievements_list[i]}, "
        message = f"Here are a list of {team_name} achievements. " \
                  f"{create_achievement_list}"
    else:
        create_achievement_list = "None"
        message = f"Unfortunately {team_name} has no achievements. "
    return message
Esempio n. 7
0
def _create_new_teams(teams, path, create=False):
    # for request to liquipedia
    dota_obj = dota(
        "KB_Parser (https://github.com/Finger228/LiquiParser; [email protected]"
    )

    # for every team get json from liquipedia api
    # parse it and get new json with need info
    # then save new json file or .scs files in path directory
    # return list of players from teams

    players = []
    for team in teams:
        team_idtf = get_idtf(team)

        if create == True:
            team_info = dota_obj.get_team_info(team, True)
            team_info = _sort_team_data(team, team_info)
            for player in team_info['roster']:
                players.append(player['nickname'])

            with open('{}/teams/{}/{}.json'.format(path, team, team_idtf),
                      'w') as f:
                f.write(json.dumps(team_info, ensure_ascii=False))
            print("Json of {} created".format(team))

        else:
            with open('{}/teams/{}/{}.json'.format(path, team, team_idtf),
                      'r') as f:
                team_info = json.load(f)

        team_info = _team_json_to_scs(team, team_idtf, team_info)

        with open('{}/teams/{}/{}.scs'.format(path, team, team_idtf),
                  'w') as r:
            r.write(team_info[0])

        with open('{}/teams/{}/{}_roster.scs'.format(path, team, team_idtf),
                  'w') as r:
            r.write(team_info[1])

        print("scs of {} created".format(team))

    return players
Esempio n. 8
0
def sync_league_baner(context):
    dota_liquipedi = dota("appname")
    leagues = get_current_leagues()
    try:
        for league in leagues:
            Session = sessionmaker(bind=engine)
            session = Session()
            row = session.query(League).filter(
                League.name == league[0]).first()
            if row.baner_url == None:
                logging.info(f"Search baner for '{league[0]}'")
                baner_url = dota_liquipedi.get_tournament_baner(league[2])
                row.baner_url = baner_url
            session.commit()
            time.sleep(30)

    except KeyError as err:
        logging.info(err)
    except json.decoder.JSONDecodeError:
        logging.info('api request is block, try "https://liquipedia.net"')
Esempio n. 9
0
import requests
from .info import id_by_name
from liquipediapy import dota

dota_obj = dota("CyberInfo")


class IndTeam:
    def __init__(self, name):
        self.name = name
        self.id = id_by_name(name)[0]
        self.players = []
        self.wins = 0
        self.coach = None
        self.captain = None
        self.country = None
        self.losses = 0
        self.logo = None
        self.index = None

    def __repr__(self):
        return f"{self.name}, {self.coach}, {self.captain}, {self.players}," \
               f" {self.country}, {self.wins}, {self.losses}"

    def fill_team_info(self, name):
        if name.lower() == "navi":
            self.name = "Natus Vincere"
            idname = id_by_name(self.name)
        else:
            idname = id_by_name(name)
            self.name = idname[1]
Esempio n. 10
0
from liquipediapy import dota

dota_obj = dota("appname")

players = dota_obj.get_players()

player_details = dota_obj.get_player_info('Miracle-', True)

team_details = dota_obj.get_team_info('Team Liquid', True)

transfers = dota_obj.get_transfers()

games = dota_obj.get_upcoming_and_ongoing_games()

heros = dota_obj.get_heros()

items = dota_obj.get_items()

patches = dota_obj.get_patches()

tournaments = dota_obj.get_tournaments()

pro_circuit_details = dota_obj.get_pro_circuit_details()
Esempio n. 11
0
 def __init__(self, app_name):
     self.app_name = app_name
     self.dota_p = dota(self.app_name)
     self.lp = liquipediapy(self.app_name, 'dota2')