Ejemplo n.º 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))
Ejemplo n.º 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}")
Ejemplo n.º 3
0
 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])
Ejemplo n.º 4
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 'Couldn\'t find player %s' % name