Skip to content

Instantly share code, notes, and snippets.

@fmarier
Created January 4, 2022 05:15
Show Gist options
  • Save fmarier/7e5a8519f206e1a8d174c58632e2e35d to your computer and use it in GitHub Desktop.
Save fmarier/7e5a8519f206e1a8d174c58632e2e35d to your computer and use it in GitHub Desktop.
Expand URLs for Brave News RSS feeds
#!/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