forked from Flobin/OnionBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss.py
31 lines (22 loc) · 813 Bytes
/
rss.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
import feedparser
import ssl
import csv
import itertools
ssl._create_default_https_context = ssl._create_unverified_context
d = feedparser.parse('https://www.theonion.com/rss')
headlines_list = []
with open('headlines.csv', 'r+') as headlines:
# check all the headlines in the rss feed
for entry in d['entries']:
# get the headline
headline = entry['title']
reader = csv.reader(headlines, delimiter=',')
# put first 1000 headlines into list, should be enough
for row in itertools.islice(reader, 1000):
headlines_list.append(row[0])
# add new headlines to csv file
if headline in headlines_list:
pass
else:
writer = csv.writer(headlines, delimiter=',')
writer.writerow([headline])