59 lines
1.4 KiB
Python
59 lines
1.4 KiB
Python
import datetime
|
|
from typing import Dict
|
|
import requests
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
import re
|
|
|
|
def get_showings(film: str) -> Dict:
|
|
r = requests.get(f"https://www.offi.fr/cinema/evenement/{film}")
|
|
|
|
soup = BeautifulSoup(r.text)
|
|
|
|
screenings = soup.find_all("div", {"id": re.compile(r"t_sceances_[a-zA-Z0-9]+")})
|
|
|
|
output = {}
|
|
|
|
for screening in screenings:
|
|
datematch = re.match(r"t_sceances_([0-9]{4})-([0-9]{2})-([0-9]{2})", screening["id"])
|
|
|
|
date = datetime.date(int(datematch.group(1)), int(datematch.group(2)), int(datematch.group(3)))
|
|
|
|
datedata = {}
|
|
|
|
links = screening.find_all("a", {"class": "text-dark"})
|
|
|
|
for link in links:
|
|
|
|
cinema = link.find("span").text
|
|
|
|
cinetimes = []
|
|
|
|
times = link.find_next("div", {"class": "event-times-container"})
|
|
|
|
for time in times.find_all("span"):
|
|
cinetimes.append(time.text)
|
|
|
|
datedata[cinema] = cinetimes
|
|
|
|
output[date] = datedata
|
|
|
|
return output
|
|
|
|
FILMS = [
|
|
"le-ciel-peut-attendre-5799",
|
|
"tideland-26007",
|
|
"sommeil-dhiver-53367",
|
|
"a-girl-at-my-door-54742",
|
|
"37-degres-2-le-matin-228",
|
|
"mission-version-restauree-92072",
|
|
"funny-games-us-30758",
|
|
"huit-et-demi-13525",
|
|
"climax-69321",
|
|
"the-first-slam-dunk-92878"
|
|
]
|
|
|
|
if __name__ == "__main__":
|
|
for film in FILMS:
|
|
print(get_showings(film)) |