Skip to content

Instantly share code, notes, and snippets.

@xflr6
Last active October 4, 2025 16:39
Show Gist options
  • Select an option

  • Save xflr6/b7756d379e77f84684bd3f60702073cb to your computer and use it in GitHub Desktop.

Select an option

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