in case there are no live races dont error
This commit is contained in:
31
pcslive.py
31
pcslive.py
@@ -4,6 +4,7 @@ import requests, time
|
||||
# class for storing the live races
|
||||
class LiveStats:
|
||||
def __init__(self):
|
||||
self.races = []
|
||||
self.refresh_races()
|
||||
|
||||
# scrapes from the PCS homepage where the little green live stats boxes are
|
||||
@@ -18,21 +19,23 @@ class LiveStats:
|
||||
# races are currently live
|
||||
live = soup.find(attrs={"class":"hp3-livestats"})
|
||||
|
||||
# also get rid of the horrible polygon number stuff !!! YUCK
|
||||
# i imagine its how the profiles are drawn. there is A LOT
|
||||
# and it makes reading the raw html very PAINFUL
|
||||
for tag in live.find_all(attrs={"class":"inverse"}):
|
||||
tag.decompose()
|
||||
# if there are even any races:
|
||||
if live:
|
||||
# also get rid of the horrible polygon number stuff !!! YUCK
|
||||
# i imagine its how the profiles are drawn. there is A LOT
|
||||
# and it makes reading the raw html very PAINFUL
|
||||
for tag in live.find_all(attrs={"class":"inverse"}):
|
||||
tag.decompose()
|
||||
|
||||
# conveniently, every race is a list item (<li>)
|
||||
# inside is the title, status (live/finished), km to go,
|
||||
# and brief situation text, but we parse that inside Race
|
||||
races = live.find_all("li")
|
||||
self.races = []
|
||||
for raw_race in races:
|
||||
# for now just create the Race object and add it to our list
|
||||
race = Race(raw_race)
|
||||
self.races.append(race)
|
||||
# conveniently, every race is a list item (<li>)
|
||||
# inside is the title, status (live/finished), km to go,
|
||||
# and brief situation text, but we parse that inside Race
|
||||
races = live.find_all("li")
|
||||
self.races = []
|
||||
for raw_race in races:
|
||||
# for now just create the Race object and add it to our list
|
||||
race = Race(raw_race)
|
||||
self.races.append(race)
|
||||
|
||||
# straightforward
|
||||
def print_races(self):
|
||||
|
||||
Reference in New Issue
Block a user