-
Notifications
You must be signed in to change notification settings - Fork 169
/
Copy pathmain.py
47 lines (34 loc) · 969 Bytes
/
main.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
from collections import defaultdict
from datetime import datetime
import shelve
from themoviedb import Movies, Tv, CACHE
from notifications import generate_mail_msg, mail_msg
SENT_CACHE = 'sent.shelve'
language = 'en'
num_pages = 3
def update_store():
mo = Movies()
mo.get_now_playing()
mo.get_upcoming()
tv = Tv()
tv.get_on_the_air()
tv.get_popular()
def load_store():
items = defaultdict(lambda: defaultdict(list))
with shelve.open(CACHE) as sh, shelve.open(SENT_CACHE) as ca:
for key in sh:
if key in ca:
continue
ca[key] = datetime.utcnow()
entry = sh[key]
try:
items[entry.kind][entry.listing].append(
entry)
except:
print(entry)
return items
if __name__ == '__main__':
update_store()
items = load_store()
content = generate_mail_msg(items)
mail_msg(content)