-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
47 lines (38 loc) · 1.57 KB
/
utils.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
import pickle
def event_soup_to_json(event_soup):
event_name = event_soup.find('div', attrs={'class': 'event'}).find('h4').text.strip()
event_id = event_soup.find('div', attrs={'class': 'event'}).find('h4').find('a')['href'].split('/')[-1]
if len(event_soup.find_all('div', attrs={'class': 'place'})) == 2:
event_place = event_soup.find_all('div', attrs={'class': 'place'})[0].find('a').text.strip()
else:
event_place = ''
event_date = event_soup.find('div', attrs={'class': 'date'}).text.strip().split()[0]
if event_soup.find_all('div', attrs={'class': 'place'}):
event_time = event_soup.find_all('div', attrs={'class': 'place'})[-1].text.strip()
else:
event_time = ''
event_actors = []
actors_list_inner = event_soup.find('div', attrs={'class': 'actor'}).find_all('li')[1:]
for actor_inner in actors_list_inner:
event_actors.append(actor_inner.text.strip())
event_json = {
'name': event_name,
'id': event_id,
'url': 'https://www.eventernote.com/events/{}'.format(event_id),
'place': event_place,
'date': event_date,
'time_str': event_time,
'actors': event_actors
}
return event_json
def load_pushed_list(dump_file):
pushed_list = dict() # {events_id: date}
try:
with open(dump_file, 'rb') as fr:
pushed_list = pickle.load(fr)
except FileNotFoundError as e:
pass
return pushed_list
def dump_pushed_list(dump_file, pushed_list):
with open(dump_file, 'wb') as fw:
pickle.dump(pushed_list, fw)