-
Notifications
You must be signed in to change notification settings - Fork 0
/
movistar.py
80 lines (52 loc) · 2.14 KB
/
movistar.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
import requests
from bs4 import BeautifulSoup
from conf import MOVISTAR_AJAX_URL, MOVISTAR_CHANNEL_LOGO_URL, MOVISTAR_DESCRIPTION_URL
from utils import clean_string
class Movistar(object):
@classmethod
def get_channels(self):
print("Getting movistar channels...")
payload = {
"action": "getChannels",
}
response = requests.post(MOVISTAR_AJAX_URL, data=payload)
response.raise_for_status()
return [ch["cod_cadena_tv"] for ch in response.json()]
@classmethod
def get_programation(self, date, channels):
print(f"Getting movistar programmes of {date}...")
payload = {
"action": "getProgramation",
"categorires": "",
"channels[]": channels,
"day": date
}
response = requests.post(MOVISTAR_AJAX_URL, data=payload)
response.raise_for_status()
return response.json()
@classmethod
def get_channel_logo(self, channel):
return MOVISTAR_CHANNEL_LOGO_URL + channel
@classmethod
def get_extra_info(self, cee):
print(f"Downloading extra info for {cee}")
info = {}
url = MOVISTAR_DESCRIPTION_URL + cee
response = requests.get(url)
response.raise_for_status()
soup = BeautifulSoup(response.content, "html.parser")
info["image"] = soup.find("img", class_="img-v-detail")["src"]
info["desc"] = soup.find("div", class_="sinopsis_large").find(text=True, recursive=False).strip()
info["details"] = {}
details = soup.find("div", class_="details_container").find_all("div")
for i in range(0, len(details) - 1, 2):
title = clean_string(details[i].text)
value_item = details[i + 1].find("span", class_="details_value")
content_list = value_item.find_all("span")
if content_list:
value = [v.text.strip() for v in content_list]
else:
value = value_item.text.strip()
info["details"][title] = value
info["age_rating"] = soup.find("span", class_="nivel_moral").text.strip()
return info