-
Notifications
You must be signed in to change notification settings - Fork 3
/
usat.py
25 lines (21 loc) · 868 Bytes
/
usat.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
import json
import feedparser
from urllib.parse import urljoin, urlparse
with open("usat_urls.json", "r") as usat_file:
usat_json = json.load(usat_file)
feeds = [
"http://rssfeeds.usatoday.com/usatoday-NewsTopStories",
"http://rssfeeds.usatoday.com/UsatodaycomNation-TopStories",
"http://rssfeeds.usatoday.com/UsatodaycomWashington-TopStories",
"http://rssfeeds.usatoday.com/UsatodaycomWorld-TopStories",
"http://rssfeeds.usatoday.com/usatoday-LifeTopStories",
"http://rssfeeds.usatoday.com/usatoday-TechTopStories"
]
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 usat_json:
usat_json.append(clean_url)
with open("usat_urls.json", "w") as f:
f.write(json.dumps(usat_json))