-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
84 lines (67 loc) · 2.32 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
This script allows you to get the results of the African Cup of Nations 2024 Round By Round
From the Eurosport website:
https://www.eurosport.fr/football/coupe-d-afrique-des-nations/calendrier-resultats.shtml
"""
from datetime import datetime as dt
import requests
import streamlit as st
from bs4 import BeautifulSoup
from polling2 import poll
URL = "https://www.eurosport.fr/football/coupe-d-afrique-des-nations/calendrier-resultats.shtml"
def get_clock_info(info):
"""
Get the clock info from the clock_info span
"""
if info:
try:
return dt.strptime(info.text, "%H:%M").strftime("%H:%M")
except ValueError:
return "⏱️" + info.text
return "✔️"
response = poll(lambda: requests.get(URL, timeout=10), step=30, poll_forever=True)
# Get the HTML content from the response
html_content = response.text
# Create a BeautifulSoup object with the HTML content
soup = BeautifulSoup(html_content, "html.parser")
# Find all divs with attribute data-testid equals "team-match-score-atom-container" or "template-section-title"
divs = soup.find_all(
"div",
attrs={
"data-testid": ["team-match-score-atom-container", "template-section-title"]
},
)
# Make the fixtures table
fixtures_table = []
MATCH_DAY = None # The current match day dd/mm/yyyy
for div in divs:
if div.get("data-testid") == "template-section-title":
# Append the round title to the fixtures table
MATCH_DAY = dt.strptime(div.text, "%d/%m/%Y").date()
# Get the children divs
else:
children = div.findChildren("div", recursive=False)
clock_info = div.findParent("div").findChild(
"span",
recursive=True,
attrs={"data-testid": "atom-match-card-content-info"},
)
# Append the fixture info to the fixtures table
fixtures_table.append(
{
"Match Day": MATCH_DAY,
"Time": get_clock_info(clock_info),
"Team A": children[0].text,
"Score": f"{children[1].text} - {children[2].text}",
"Team B": children[3].text,
}
)
MATCH_DAY = ""
st.title("African Cup of Nations 2024")
st.write("Current Round")
st.dataframe(
fixtures_table,
hide_index=True,
height=458,
use_container_width=True,
)