Skip to content

Instantly share code, notes, and snippets.

@xflr6
Last active December 18, 2021 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xflr6/b7756d379e77f84684bd3f60702073cb to your computer and use it in GitHub Desktop.
Save xflr6/b7756d379e77f84684bd3f60702073cb to your computer and use it in GitHub Desktop.
Compare RSS feed enclosure length with content-length header of file when downloading the URL
"""Compare feed enclosure length with content-length of file url."""
import urllib.request
import xml.etree.ElementTree as etree
URL = 'https://feeds.feedburner.com/thebuglefeed?format=xml'
with urllib.request.urlopen(URL) as f:
tree = etree.parse(f)
for item in tree.getroot().iterfind('channel/item/enclosure'):
url = item.attrib['url']
_, _, filename = url.rpartition('/')
feedsize = int(item.attrib['length'])
with urllib.request.urlopen(url) as f:
size = int(f.headers['Content-Length'])
flag = '!' if feedsize != size else ''
print(f'{filename:50.50} {feedsize:d}\t{size:d} {flag}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment