-
Notifications
You must be signed in to change notification settings - Fork 0
/
feedHandler.py
38 lines (28 loc) · 1.08 KB
/
feedHandler.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
import feedparser
from config import RSS_URL
from datetime import datetime,timedelta
from dateutil import parser
def get_timed_digest(categories,time):
feed = feedparser.parse(RSS_URL)
now = datetime.now()
one_day_ago = datetime(now.year, now.month, now.day, int(time[:2]), int(time[3:]))- timedelta(days=1)
digest = []
for post in feed.entries:
news = dict()
if post.tags[0].term in categories and one_day_ago < parser.parse(post['published']).replace(tzinfo=None):
news['title'] = post.title
news['link'] = post.link
digest.append(news)
return digest
def get_immediately_digest():
feed = feedparser.parse(RSS_URL)
now = datetime.now()
one_day_ago = datetime(now.year, now.month, now.day, now.hour, now.minute)- timedelta(days=1)
digest = []
for post in feed.entries:
news = dict()
if one_day_ago < parser.parse(post['published']).replace(tzinfo=None):
news['title'] = post.title
news['link'] = post.link
digest.append(news)
return digest