in case there are no live races dont error

This commit is contained in:
cube
2026-05-30 22:00:59 +01:00
parent 1e665d45b7
commit 04dcb8c876

View File

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