コード例 #1
0
def get_results():
    results = get_parsed_page("http://www.hltv.org/results/")

    results_list = []

    pastresults = results.find_all("div", {"class": "results-holder"})

    for result in pastresults:
        resultDiv = result.find_all("div", {"class": "result-con"})

        for res in resultDiv:
            getRes = res.find("div", {"class": "result"}).find("table")

            resultObj = {}

            if (res.parent.find("span", {"class": "standard-headline"})):
                resultObj['date'] = res.parent.find(
                    "span", {
                        "class": "standard-headline"
                    }).text.encode('utf8')
            else:
                dt = datetime.date.today()
                resultObj['date'] = str(dt.day) + '/' + str(
                    dt.month) + '/' + str(dt.year)

            if (res.find("td", {"class": "placeholder-text-cell"})):
                resultObj['event'] = res.find("td", {
                    "class": "placeholder-text-cell"
                }).text.encode('utf8')
            elif (res.find("td", {"class": "event"})):
                resultObj['event'] = res.find("td", {
                    "class": "event"
                }).text.encode('utf8')
            else:
                resultObj['event'] = None

            if (res.find_all("td", {"class": "team-cell"})):
                resultObj['team1'] = res.find_all(
                    "td", {"class": "team-cell"
                           })[0].text.encode('utf8').lstrip().rstrip()
                resultObj['team1score'] = converters.to_int(
                    res.find("td", {
                        "class": "result-score"
                    }).find_all("span")[0].text.encode(
                        'utf8').lstrip().rstrip())
                resultObj['team2'] = res.find_all(
                    "td", {"class": "team-cell"
                           })[1].text.encode('utf8').lstrip().rstrip()
                resultObj['team2score'] = converters.to_int(
                    res.find("td", {
                        "class": "result-score"
                    }).find_all("span")[1].text.encode(
                        'utf8').lstrip().rstrip())
            else:
                resultObj['team1'] = None
                resultObj['team2'] = None

            results_list.append(resultObj)

    return results_list
コード例 #2
0
def top30teams():
    page = get_parsed_page("http://www.hltv.org/ranking/teams/")
    teams = page.find("div", {"class": "ranking"})
    teamlist = []
    for team in teams.find_all("div", {"class": "ranked-team standard-box"}):
        newteam = {
            'name':
            team.find('div', {
                "class": "ranking-header"
            }).select('.name')[0].text.strip(),
            'rank':
            converters.to_int(team.select('.position')[0].text.strip(),
                              regexp=True),
            'rank-points':
            converters.to_int(team.find('span', {
                'class': 'points'
            }).text,
                              regexp=True),
            'team-id':
            converters.to_int(
                team.find(
                    'a',
                    {'class': 'details moreLink'})['href'].split('/')[-1]),
            'team-players': []
        }
        for player_div in team.find_all("td", {"class": "player-holder"}):
            player = {}
            player['name'] = player_div.find(
                'img', {'class': 'playerPicture'})['title']
            player['player-id'] = converters.to_int(
                player_div.select('.pointer')[0]['href'].split("/")[-2])
            newteam['team-players'].append(player)
        teamlist.append(newteam)
    return teamlist
コード例 #3
0
ファイル: main.py プロジェクト: s14002/hltv-api
def top20teams():
    page = get_parsed_page("http://www.hltv.org/ranking/teams/")
    teams = page.select("div.ranking-box")
    teamlist = []
    for team in teams:
        newteam = {'name': team.select('.ranking-teamName > a')[0].text.strip(),
                   'rank': converters.to_int(team.select('.ranking-number')[0].text.strip(), regexp=True),
                   'rank-points': converters.to_int(team.select('.ranking-teamName > span')[0].text, regexp=True),
                   'team-id': converters.to_int(team.select('.ranking-delta')[0].get('id'), regexp=True),
                   'team-players': []}
        for player_div in team.select('.ranking-lineup > div'):
            player = {}
            player_anchor = player_div.select('.ranking-playerNick > a')[0]
            player['name'] = player_anchor.text.strip()
            player_link = player_anchor.get('href')
            if 'pageid' in player_link:
                player['player-id'] = converters.to_int(player_link[player_link.index('playerid'):], regexp=True)
            else:
                player['player-id'] = converters.to_int(player_link, regexp=True)
            if player['name'].startswith("[email"):
                player_page = get_parsed_page(str("http://www.hltv.org" + player_anchor['href']))
                player['name'] = player_page.title.text.split()[0]
            newteam['team-players'].append(player)
        teamlist.append(newteam)
    return teamlist
コード例 #4
0
ファイル: main.py プロジェクト: s14002/hltv-api
def get_matches():
    matches = get_parsed_page("http://www.hltv.org/matches/")
    matchlist = matches.find_all("div", {"class": ["matchListBox", "matchListDateBox"]})
    datestring = ""
    matches_list = []
    for match in matchlist:
        if match['class'][0] == "matchListDateBox":
            # TODO possibly change this into real date object
            datestring = match.text.strip()
        else:
            try:
                #What does matchd mean?
                matchd = {}
                matchd['date'] = datestring + " - " + match.find("div", {"class": "matchTimeCell"}).text.strip()
                team1div = match.find("div", {"class": "matchTeam1Cell"})
                team1 = {}
                team1["name"] = team1div.text.strip()
                team1href = team1div.select('a')[0].get('href')
                team1["id"] = converters.to_int(team1href[team1href.index('teamid'):], regexp=True)
                matchd['team1'] = team1
                team2div = match.find("div", {"class": "matchTeam2Cell"})
                team2 = {}
                team2["name"] = team2div.text.strip()
                team2href = team2div.select('a')[0].get('href')
                team2["id"] = converters.to_int(team2href[team2href.index('teamid'):], regexp=True)
                matchd['team2'] = team2

                # include link (id) to match page
                matchd['matchid'] = match.find("div", {"class": "matchActionCell"}).find("a").get('href') #What a f*****g mess lmao

                matches_list.append(matchd)
            except:
                # what does this do man?
                print(match.text[:7].strip(), match.text[7:-7].strip())
    return matches_list
コード例 #5
0
ファイル: scraper.py プロジェクト: Brendan-Song/elearner
def get_results():
    results = get_parsed_page("http://www.hltv.org/results/")
    resultslist = results.find_all(
        "div", {"class": ["matchListBox", "matchListDateBox"]})
    datestring = ""
    results_list = []
    for result in resultslist:
        if result['class'][0] == "matchListDateBox":
            # TODO possibly change this into a real date object
            datestring = result.text.strip()
        else:
            #What does resultd mean?
            resultd = {}
            #This page uses the time box to show map played
            resultd['date'] = datestring
            resultd['map'] = result.find("div", {
                "class": "matchTimeCell"
            }).text.strip()
            scores = result.find("div", {
                "class": "matchScoreCell"
            }).text.strip()

            #Team 1 info
            team1div = result.find("div", {"class": "matchTeam1Cell"})
            team1 = {}
            team1['name'] = team1div.text.strip()
            #I seem to get the ID slightly differently, still works fine though
            team1href = team1div.select('a')[0].get('href')
            team1['id'] = converters.to_int(team1href.split("=")[-1],
                                            regexp=True)
            team1['score'] = converters.to_int(scores.split("-")[0].strip(),
                                               regexp=True)
            resultd['team1'] = team1

            #Team 2 info
            team2div = result.find("div", {"class": "matchTeam2Cell"})
            team2 = {}
            team2['name'] = team2div.text.strip()
            team2href = team2div.select('a')[0].get('href')
            team2['id'] = converters.to_int(team2href.split("=")[-1],
                                            regexp=True)
            team2['score'] = converters.to_int(scores.split("-")[1].strip(),
                                               regexp=True)
            resultd['team2'] = team2

            resultd['matchid'] = result.find("div", {
                "class": "matchActionCell"
            }).find("a").get('href')  #What a f*****g mess lmao

            results_list.append(resultd)
    return (results_list)
コード例 #6
0
ファイル: main.py プロジェクト: s14002/hltv-api
def _get_lineup(player_anchors):
    """
    helper function for function above
    :return: list of players
    """
    players = []
    for player_anchor in player_anchors:
        player = {}
        player_link = player_anchor.get('href')
        player['player-id'] = converters.to_int(player_link[player_link.index('playerid'):], regexp=True)
        player_text = player_anchor.text
        player['name'] = player_text[0:player_text.index("(")].strip()
        player['maps-played'] = converters.to_int(player_text[player_text.index("("):], regexp=True)
        players.append(player)
    return players
コード例 #7
0
def find_subprocesses(pid):
    cmd = "ps -ef | grep -v grep | grep -w %d | awk '{print $2}'" % pid
    logger.info("Run find subprocesses of %d command: %s" % (pid, cmd))
    out = os.popen(cmd).read().strip()
    current_pid = os.getpid()
    subpids = [converters.to_int(x) for x in out.split("\n")]
    subpids = filter(lambda x: x > 0 and x not in (pid, current_pid), subpids)
    return subpids
コード例 #8
0
ファイル: parser.py プロジェクト: s1ns1ns1n/TGbot
def top5teams():
    page = get_parsed_page("http://www.hltv.org/ranking/teams/")
    teams = page.find("div", {"class": "ranking"})
    teams5 = []
    for team in teams.find_all("div", {"class": "ranked-team standard-box"}):
        newteam = {'name': team.find('div', {"class": "ranking-header"}).select('.name')[0].text.strip(),
                   'rank': converters.to_int(team.select('.position')[0].text.strip(), regexp=True),
                   'rank-points': converters.to_int(team.find('span', {'class': 'points'}).text, regexp=True),
                   'team-players': []
                   }
        for player_div in team.find_all("td", {"class": "player-holder"}):
            player = {}
            player['player_name'] = player_div.find('img', {'class': 'playerPicture'})['title']
            newteam['team-players'].append(player)
        if len(teams5)<5:
         teams5.append(newteam)
    return teams5
コード例 #9
0
ファイル: hltv.py プロジェクト: LezdCS/Bot-Discord-CS
def top30teams():
    global teamlist, teamnameclassement, teampointsclassement, teamchangeclassement
    page = get_parsed_page("http://www.hltv.org/ranking/teams/")
    teams = page.find("div", {"class": "ranking"})
    teamlist = []
    teamnameclassement = []
    teampointsclassement = []
    teamchangeclassement = []
    for team in teams.find_all("div", {"class": "ranked-team standard-box"}):
        newteam = {
            'name':
            team.find('div', {
                "class": "ranking-header"
            }).select('.name')[0].text.strip(),
            'rank':
            converters.to_int(team.select('.position')[0].text.strip(),
                              regexp=True),
            'rank-points':
            converters.to_int(team.find('span', {
                'class': 'points'
            }).text,
                              regexp=True),
            'team-id':
            converters.to_int(
                team.find(
                    'a', {'class': 'details moreLink'})['href'].split('/')[-1])
        }
        teamnameclassement.append(
            team.find('div', {
                "class": "ranking-header"
            }).select('.name')[0].text.strip())
        teampointsclassement.append(
            str(
                converters.to_int(team.find('span', {
                    'class': 'points'
                }).text,
                                  regexp=True)))
        changement = team.find('div', {
            "class": "change"
        }).text  # CHANHGEMENT DEP POSITION DANS LE CLASSEMENT
        changement = changement.split('>')

        teamchangeclassement.append(changement[0])
        teamlist.append(newteam)
    return teamlist
コード例 #10
0
def check_daemon():
    pid = -1
    try:
        fpr = open(daemon_config.pidfile, "r")
        pidstr = fpr.read().strip()
        fpr.close()
        pid = converters.to_int(pidstr, -1)
    except:
        pass
    if pid > 0:
        command = "ps -ef | grep -w %d | grep -v grep" % pid
        logger.info("Check <%s> command: %s" %
                    (daemon_config.app_daemon_name, command))
        out = os.popen(command).read().strip()
        return bool(out)
    else:
        return False
コード例 #11
0
ファイル: main.py プロジェクト: s14002/hltv-api
def top_players():
    page = get_parsed_page("http://www.hltv.org/?pageid=348&statsfilter=10&mapid=0")
    boxes = page.find_all("div", {"class": "framedBox"})
    top_player_categories = []
    for box in boxes:
        category_obj = {'category': box.find("h2").text}
        players = []
        for player_elem in box.select("> div"):
            player = {}
            player_link = player_elem.find('a')
            player['name'] = player_link.text
            player['team'] = player_elem.text.split("(")[1].split(")")[0]
            p_url = player_link['href']
            player['player-id'] = converters.to_int(p_url[p_url.index('playerid=')+9:p_url.index('&statsfilter')])
            player['stat'] = player_elem.select('div:nth-of-type(2)')[0].text
            players.append(player)
        category_obj['players'] = players
        top_player_categories.append(category_obj)
    return top_player_categories
コード例 #12
0
def stop_first_subprocesses():
    pid = -1
    try:
        fpr = open(daemon_config.pidfile, "r")
        pidstr = fpr.read().strip()
        fpr.close()
        pid = converters.to_int(pidstr, -1)
    except:
        pass
    # stop all: ps -ef | grep -w 25926 | grep -v grep | awk '{print $2}' | xargs kill
    if pid > 0:
        command = "ps -ef | grep -w %d | grep -v grep | awk '{print $2}' | xargs kill" % pid
        logger.info("Stop <%s> command: %s" %
                    (daemon_config.app_daemon_name, command))
        os.system(command)
        os.remove(daemon_config.pidfile)
        logger.info("Program <%s> has stopped!" %
                    daemon_config.app_daemon_name)
    else:
        logger.info("Program <%s> is not running!" %
                    daemon_config.app_daemon_name)
コード例 #13
0
def stop_daemon(signal=None):
    pid = -1
    try:
        fpr = open(daemon_config.pidfile, "r")
        pidstr = fpr.read().strip()
        fpr.close()
        pid = converters.to_int(pidstr, -1)
    except:
        pass
    if pid > 0:
        logger.info("Try to stop <%s>, command: %s" %
                    (daemon_config.app_daemon_name, command))
        all_pids = find_all_subprocesses()
        all_pids_str = " ".join(map(str, all_pids))
        logger.info("Get all pids for <%s>, detail: %s." %
                    (daemon_config.app_daemon_name, all_pids_str))
        ret = stop_processes(all_pids, signal)
        logger.info("Program <%s> has stopped, kill return code is %d!" %
                    (daemon_config.app_daemon_name, ret))
    else:
        logger.info("Program <%s> is not running!" %
                    daemon_config.app_daemon_name)