Created
January 4, 2022 05:15
-
-
Save fmarier/7e5a8519f206e1a8d174c58632e2e35d to your computer and use it in GitHub Desktop.
Expand URLs for Brave News RSS feeds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import csv | |
import requests | |
from urllib.parse import urlparse, urlunparse | |
def feedburner_upgrade(url): | |
parsed = urlparse(url) | |
if parsed.netloc in ('feeds2.feedburner.com', 'feeds.feedburner.com', 'feedproxy.google.com'): | |
return parsed._replace(scheme='https').geturl() | |
return url | |
def resolve_url(url): | |
try: | |
r = requests.get(url, timeout=30) | |
return r.url | |
except: | |
print("ERROR: %s" % url) | |
return url | |
def main(): | |
with open('sources2.csv', 'w') as outfile: | |
writer = csv.writer(outfile) | |
with open('sources.csv', newline='') as infile: | |
reader = csv.reader(infile) | |
seen_first = False | |
for row in reader: | |
if seen_first: | |
url = row[1] | |
r_url = resolve_url(url) | |
final_url = feedburner_upgrade(r_url) | |
if final_url != url: | |
print("%s -> %s" % (url, final_url)) | |
row[1] = final_url | |
writer.writerow(row) | |
seen_first = True | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment