-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhbos.cr.py
55 lines (46 loc) · 1.48 KB
/
hbos.cr.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
from bs4 import BeautifulSoup
import requests
import json
import datetime
from calendar import monthrange
STARTING_DAY = datetime.date.today().day
MONTH = datetime.date.today().month
NEXTMONTH = MONTH+1
MAXDAYS = 30
INITIALCOUNT = 1
def scrap_by_month(day,month,count):
max_days = monthrange(2018, month)[1]
count = count
for i in range(day, max_days+2):
print(count)
if(count == MAXDAYS):
break
elif (i == max_days+1):
scrap_by_month(1,month+1,count)
else:
scrap_that(i, month)
count = count + 1
def scrap_that(day,month):
url_template = f'https://br.hbomax.tv/ajax.programacion-canal.html?pid=4&cul=pt&oid=4&fecha={month}/{day}/2018'
data = requests.get(url_template).text
soup = BeautifulSoup(data,'lxml')
main = soup.find_all('tbody')
list_of_channels = ['HBO','HBO2','HBOPLUS','HBOPLUS','HBOFAMILY','HBOSIGNATURE','MAX','MAXUP','MAXPRIME','MAXPRIME']
for i, channel in enumerate(main):
movies = channel.find_all('tr')
for movie_detail in movies:
try:
obj = {}
obj['day'] = day
obj['month'] = month
obj['channel_name'] = list_of_channels[i]
obj['title'] = movie_detail.find('h5', class_='estilo-titulo-gris').text.strip()
obj['img'] = movie_detail.find('img').get('src')
obj['hour_start'] = movie_detail.find('h5').text.strip()
list_of_stuff.append(obj)
except AttributeError:
break
list_of_stuff=[]
scrap_by_month(STARTING_DAY,MONTH,INITIALCOUNT)
with open('hbos_info.json', 'w') as f:
json.dump(list_of_stuff, f)