can now get the situation diagram from the race stats page
This commit is contained in:
36
pcslive.py
36
pcslive.py
@@ -6,6 +6,9 @@ class LiveStats:
|
||||
self.refresh_live()
|
||||
self.get_races()
|
||||
|
||||
self.timeline = []
|
||||
self.situation_long = []
|
||||
|
||||
def refresh_live(self):
|
||||
req = requests.get("https://www.procyclingstats.com/")
|
||||
html = req.text
|
||||
@@ -60,15 +63,20 @@ class Race:
|
||||
print("")
|
||||
print(self.url)
|
||||
|
||||
def get_timeline(self):
|
||||
def get_race_page(self):
|
||||
if self.url != "None":
|
||||
full_url = "https://www.procyclingstats.com/" + self.url
|
||||
|
||||
req = requests.get(full_url)
|
||||
html = req.text
|
||||
soup = BeautifulSoup(html, "html.parser")
|
||||
return soup
|
||||
return None
|
||||
|
||||
all = soup.find_all(attrs={"class":"timeline3cont"})
|
||||
def get_timeline(self):
|
||||
page = self.get_race_page()
|
||||
if page:
|
||||
all = page.find_all(attrs={"class":"timeline3cont"})
|
||||
live = all[0]
|
||||
timeline = live.find_all("li")
|
||||
self.timeline = []
|
||||
@@ -78,6 +86,30 @@ class Race:
|
||||
stat_content = stat.find(attrs={"class":"textCont"})
|
||||
self.timeline.append(self.remove_tags(stat_content))
|
||||
|
||||
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")
|
||||
self.situation_long = {}
|
||||
last_timegap = None
|
||||
for item in situation_long:
|
||||
#print(item)
|
||||
time_gap = item.find(attrs={"class":"time"})
|
||||
group_name = item.find(attrs={"class":"groupname"})
|
||||
rider = item.find(attrs={"class":"maxw200"})
|
||||
|
||||
if time_gap:
|
||||
tg = self.remove_tags(time_gap)
|
||||
self.situation_long[tg] = []
|
||||
last_timegap = tg
|
||||
rider_name = self.remove_tags(rider)
|
||||
if rider_name not in self.situation_long[last_timegap]:
|
||||
self.situation_long[last_timegap].append(rider_name)
|
||||
|
||||
#print(self.remove_tags(time_gap), self.remove_tags(group_name), self.remove_tags(riders))
|
||||
|
||||
|
||||
def remove_tags(self, text):
|
||||
text = str(text)
|
||||
|
||||
Reference in New Issue
Block a user