diff --git a/pcslive.py b/pcslive.py index 3dc5fdf..f36ae73 100644 --- a/pcslive.py +++ b/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 (
  • ) - # 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 (
  • ) + # 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):