当前位置: 首页>>代码示例>>Python>>正文


Python Team.wins方法代码示例

本文整理汇总了Python中models.Team.wins方法的典型用法代码示例。如果您正苦于以下问题:Python Team.wins方法的具体用法?Python Team.wins怎么用?Python Team.wins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Team的用法示例。


在下文中一共展示了Team.wins方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getMatchups

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import wins [as 别名]
def getMatchups(soup, _cshTeam, url):
    """
    Gets every team's data given the CSH team's name and url. Gathers the
    scores, dates for upcoming games, and opposing teams stats. Stores the
    information into the database after making the appropriate objects.
    """
    x = soup.find_all(text=re.compile(_cshTeam))
    _csh_wins = 0
    _csh_losses = 0
    _csh_ties = 0
    # sportContent = soup.find_all("div", { "class" : "popover-content" })[0]
    # li = sportContent.find_all("li")[2]
    # _sport = li.find_next("a").get_text()
    title = soup.title.string
    _sport = title.split("/")[1]
    # header = soup.find(id="ctl00_ucSiteHeader_divHeaderBox")
    header = soup.find("a", {"class": "school-logo"})
    csh_picture = header.find_next("img").get("src")
    try:
        cshTeam = Team.objects.get(link=url)
    except:
        cshTeam = None
    if cshTeam:
        cshTeam.picture = csh_picture
        cshTeam.save()
    else:
        cshTeam = Team(
            link=url,
            sport=_sport,
            name=_cshTeam,
            wins=_csh_wins,
            losses=_csh_losses,
            ties=_csh_ties,
            picture=csh_picture,
            rank=0,
            iscsh=True,
            season=Season.objects.all()[0].season,
        )
        cshTeam.save()
    matchList = list(cshTeam.CSH.all())
    overall = soup.find(id="ctl00_ContentPlaceHolder2_ucTeamRelated_pnlTeamSchedule")
    teamSchedule = overall.find_next("tbody")
    if teamSchedule == None:
        print("No team schedule found.")
    else:
        counter = 0
        teams = teamSchedule.find_all("tr")
        year = overall.get_text()[1:5]
        endofyear = False
        for i in range(len(teams) // 2):
            match = teams[counter].find_all("td")
            _clean_date = match[0].get_text() + " " + year
            if _clean_date.split(" ")[1] == "Dec":
                endofyear = True
            if endofyear == True and _clean_date.split(" ")[1] != "Dec":
                newyear = str(int(_clean_date.split(" ")[3]) + 1)
                _clean_date = match[0].get_text() + " " + newyear
            opponent = match[1].get_text().split("  ")
            _enemyTeam = opponent[1]
            loc = opponent[0]  # gets whether it is VS or @
            result = match[2].get_text().split()
            print(result)
            _outcome = result[0]  # gets whether it was a W or L or T
            if (_outcome != "W") and (_outcome != "L") and (_outcome != "T"):  # if matchup hasn't happened yet
                _outcome = None
                _upcoming = match[2].get_text()
            elif len(result) < 4:
                _outcome = None
                _upcoming = "Awaiting Scores..."
            else:
                if loc == "VS":
                    _cshScore = result[1]
                    _enemyScore = result[3]
                else:
                    _cshScore = result[3]
                    _enemyScore = result[1]
            record = match[4].get_text().split("-")
            _wins = record[0]
            _losses = record[1]
            _ties = record[2]
            enemyUrl = match[1].find_next("a").get("href")
            pictureLink = match[1].find_next("img").get("src")
            if "DefaultLogo" in pictureLink:
                _picture = pictureLink
            else:
                _picture = getPicture(pictureLink)
            if _outcome == "W":
                _csh_wins += 1
            elif _outcome == "L":
                _csh_losses += 1
            elif _outcome == "T":
                _csh_ties += 1
            _date = datetime.strptime(_clean_date, "%a, %b %d %Y")
            print(_date)
            counter += 2
            try:
                enemyTeam = Team.objects.get(link=enemyUrl)
            except:
                enemyTeam = None
            if enemyTeam:
#.........这里部分代码省略.........
开发者ID:TalCohen,项目名称:CSHSports,代码行数:103,代码来源:parse.py


注:本文中的models.Team.wins方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。