コード例 #1
0
 def datestr_to_date(datestr):
     """
     @param datestr [str]: "MON DD, H:MM PM EST"
                           (e.g. "NOV 29, 6:00 PM EST")
                           "MM/DD H:MM PM EST"
                           (e.g. "02/18 7:00 PM EST")
     @return [datetime.date]
     """
     if "," in datestr:
         return get_date_yearless(datestr.split(",")[0])
     else:
         datenum = datestr.split(" ")[0]
         month, day = [int(s) for s in datenum.split("/")]
         monthstr = datetime.date(1900, month, 1).strftime("%b")
         return get_date_yearless("%s %s" % (monthstr, day))
コード例 #2
0
def run():
    response = requests.get(URL)
    soup = BeautifulSoup(response.text, "html5lib")
    rows = []
    player = date = status = comment = None
    for tr in soup.find_all("tbody")[0].children:
        row = [td for td in tr if hasattr(tr, "children")]
        if player and date and status:
            if len(row) == 1 and "Comment:" in row[0].contents[0].string:
                Injury.objects.update_or_create(
                    player=player,
                    date=date,
                    comment=unicode(row[0].contents[-1]),
                    defaults={"status": status},
                )
            else:
                Injury.objects.update_or_create(player=player,
                                                date=date,
                                                defaults={"status": status})
            player = date = status = comment = None
        if len(row) == 3:
            name, status, datestr = [r.string for r in row]
            if name != "NAME" and status != "STATUS" and datestr != "DATE":
                date = get_date_yearless(datestr)
                try:
                    player = Player.get_by_name(name)
                except Player.DoesNotExist:
                    print(f"Couldn't find player {name}")
コード例 #3
0
ファイル: dkresults.py プロジェクト: dychen/fantasia
 def datestr_to_date(datestr):
     """
     @param datestr [str]: "MON DD, H:MM PM EST"
                           (e.g. "NOV 29, 6:00 PM EST")
     @return [datetime.date]
     """
     return get_date_yearless(datestr.split(',')[0])
コード例 #4
0
ファイル: injuries.py プロジェクト: dychen/fantasia
def run():
    response = requests.get(URL)
    soup = BeautifulSoup(response.text, 'html5lib')
    rows = []
    player = date = status = comment = None
    for tr in soup.find_all('tbody')[0].children:
        row = [td for td in tr if hasattr(tr, 'children')]
        if player and date and status:
            if len(row) == 1 and 'Comment:' in row[0].contents[0].string:
                Injury.objects.update_or_create(
                    player=player,
                    date=date,
                    comment=unicode(row[0].contents[-1]),
                    defaults={ 'status': status }
                )
            else:
                Injury.objects.update_or_create(
                    player=player,
                    date=date,
                    defaults={ 'status': status }
                )
            player = date = status = comment = None
        if len(row) == 3:
            name, status, datestr = [r.string for r in row]
            if name != 'NAME' and status != 'STATUS' and datestr != 'DATE':
                date = get_date_yearless(datestr)
                try:
                    player = Player.get_by_name(name)
                except Player.DoesNotExist:
                    print 'Couldn\'t find player %s' % name