-
Notifications
You must be signed in to change notification settings - Fork 25
/
conciertos.py
56 lines (40 loc) · 1.26 KB
/
conciertos.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
import json
from datetime import datetime
from dataclasses import dataclass
from robobrowser import RoboBrowser
@dataclass
class Concierto:
titulo: str
fecha: datetime.date
@staticmethod
def parse(evento):
try:
info = json.loads(evento.select("script")[0].text)[0]
titulo = info["name"]
fecha = info["startDate"].split("T")[0]
fecha = datetime.strptime(fecha, "%Y-%m-%d").date()
return Concierto(
titulo,
fecha,
)
except:
return None
def fetch_conciertos():
browser = RoboBrowser(parser="html.parser")
browser.open("https://www.songkick.com/venues/4514007-estadio-river-plate/calendar")
conciertos = []
for el in browser.select(".microformat"):
concierto = Concierto.parse(el)
if concierto:
conciertos.append(concierto)
return conciertos
def hay_concierto(dt: datetime):
fecha = dt.date()
conciertos = fetch_conciertos()
for c in conciertos:
if c.fecha != fecha:
continue
return True, c
return False, None
if __name__ == "__main__":
print(hay_concierto(datetime.today()))