-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwapo.py
18 lines (14 loc) · 888 Bytes
/
wapo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import json
import feedparser
from urllib.parse import urljoin, urlparse
with open("wapo_urls.json", "r") as wapo_file:
wapo_json = json.load(wapo_file)
feeds = ["https://feeds.washingtonpost.com/rss/politics", "https://feeds.washingtonpost.com/rss/national", "https://feeds.washingtonpost.com/rss/world", "https://feeds.washingtonpost.com/rss/business", "https://feeds.washingtonpost.com/rss/business/technology", "https://feeds.washingtonpost.com/rss/sports", "https://feeds.washingtonpost.com/rss/lifestyle", "https://feeds.washingtonpost.com/rss/entertainment"]
for url in feeds:
feed = feedparser.parse(url)
for article in feed.entries:
clean_url = urljoin(article['link'], urlparse(article['link']).path)
if not clean_url in wapo_json:
wapo_json.append(clean_url)
with open("wapo_urls.json", "w") as f:
f.write(json.dumps(wapo_json))