improvement to situation_long based on todays ethias race
This commit is contained in:
@@ -1,14 +1,17 @@
|
|||||||
from pcslive import LiveStats
|
from pcslive import LiveStats
|
||||||
import time
|
|
||||||
|
|
||||||
stats = LiveStats()
|
stats = LiveStats()
|
||||||
|
|
||||||
# if there are live races...
|
from pcslive import LiveStats
|
||||||
if len(stats.races) > 0:
|
|
||||||
race = stats.races[0]
|
|
||||||
|
|
||||||
race.get_situation_long()
|
stats = LiveStats()
|
||||||
|
race = stats.find_race("ethias")
|
||||||
|
race.get_situation_long()
|
||||||
|
|
||||||
# whats the situation? :)
|
if race.situation_long:
|
||||||
for x in race.situation_long:
|
for group in race.situation_long:
|
||||||
print(x, race.situation_long[x])
|
for item in group:
|
||||||
|
print(item)
|
||||||
|
print("================")
|
||||||
|
else:
|
||||||
|
print("No situation data")
|
||||||
72
pcslive.py
72
pcslive.py
@@ -202,36 +202,60 @@ class Race:
|
|||||||
|
|
||||||
# creates a dictionary containing time gaps as keys and each
|
# creates a dictionary containing time gaps as keys and each
|
||||||
# timegap points to a list of riders in that group
|
# timegap points to a list of riders in that group
|
||||||
|
# def get_situation_long(self):
|
||||||
|
# page = self.get_race_page()
|
||||||
|
# if page:
|
||||||
|
# all = page.find_all(attrs={"class":"situCont"})
|
||||||
|
# live = all[0]
|
||||||
|
# situation_long = live.find_all("li")
|
||||||
|
|
||||||
|
# # create the dictionary
|
||||||
|
# self.situation_long = {}
|
||||||
|
|
||||||
|
# # last_timegap is used for grouping riders together
|
||||||
|
# last_timegap = None
|
||||||
|
|
||||||
|
# for item in situation_long:
|
||||||
|
# time_gap = item.find(attrs={"class":"time"})
|
||||||
|
# rider = item.find(attrs={"class":"maxw200"})
|
||||||
|
|
||||||
|
# # time gap is only listed once and subsequent riders in that
|
||||||
|
# # group don't have one (None)
|
||||||
|
# if time_gap:
|
||||||
|
# tg = self.remove_tags(time_gap) # get rid of html tags
|
||||||
|
# self.situation_long[tg] = [] # create the list inside the dict
|
||||||
|
# last_timegap = tg # set last timegap for the loop
|
||||||
|
|
||||||
|
# rider_name = self.remove_tags(rider) # remove tags from rider name
|
||||||
|
# # the leading rider is basically the group name i guess?
|
||||||
|
# # anyway we dont need it twice
|
||||||
|
# if rider_name not in self.situation_long[last_timegap]:
|
||||||
|
# # add rider to list of riders under that timegap/group
|
||||||
|
# self.situation_long[last_timegap].append(rider_name)
|
||||||
|
|
||||||
def get_situation_long(self):
|
def get_situation_long(self):
|
||||||
page = self.get_race_page()
|
page = self.get_race_page()
|
||||||
if page:
|
if page:
|
||||||
all = page.find_all(attrs={"class":"situCont"})
|
all = page.find_all(attrs={"class":"situCont"})
|
||||||
live = all[0]
|
if all:
|
||||||
situation_long = live.find_all("li")
|
live = all[0]
|
||||||
|
groups = live.find_all(attrs={"class":"group"})
|
||||||
|
self.situation_long = []
|
||||||
|
for group in groups:
|
||||||
|
group_name = group.find(attrs={"class":"groupname"})
|
||||||
|
time = group.find(attrs={"class":"time"})
|
||||||
|
riders = group.find_all("li")
|
||||||
|
riders_clean = []
|
||||||
|
for rider in riders:
|
||||||
|
rider_name = rider.find(attrs={"class":"maxw180"})
|
||||||
|
riders_clean.append(self.remove_tags(rider_name))
|
||||||
|
group_name_clean = self.remove_tags(group_name)
|
||||||
|
time_clean = self.remove_tags(time).strip("??")
|
||||||
|
self.situation_long.append([group_name_clean, time_clean, riders_clean])
|
||||||
|
else:
|
||||||
|
self.situation_long = None
|
||||||
|
|
||||||
# create the dictionary
|
|
||||||
self.situation_long = {}
|
|
||||||
|
|
||||||
# last_timegap is used for grouping riders together
|
|
||||||
last_timegap = None
|
|
||||||
|
|
||||||
for item in situation_long:
|
|
||||||
time_gap = item.find(attrs={"class":"time"})
|
|
||||||
rider = item.find(attrs={"class":"maxw200"})
|
|
||||||
|
|
||||||
# time gap is only listed once and subsequent riders in that
|
|
||||||
# group don't have one (None)
|
|
||||||
if time_gap:
|
|
||||||
tg = self.remove_tags(time_gap) # get rid of html tags
|
|
||||||
self.situation_long[tg] = [] # create the list inside the dict
|
|
||||||
last_timegap = tg # set last timegap for the loop
|
|
||||||
|
|
||||||
rider_name = self.remove_tags(rider) # remove tags from rider name
|
|
||||||
# the leading rider is basically the group name i guess?
|
|
||||||
# anyway we dont need it twice
|
|
||||||
if rider_name not in self.situation_long[last_timegap]:
|
|
||||||
# add rider to list of riders under that timegap/group
|
|
||||||
self.situation_long[last_timegap].append(rider_name)
|
|
||||||
|
|
||||||
# remove surrounding html tags from final data points,
|
# remove surrounding html tags from final data points,
|
||||||
# like rider names, race names, etc.
|
# like rider names, race names, etc.
|
||||||
|
|||||||
Reference in New Issue
Block a user