Last active
December 18, 2021 00:13
-
-
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
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
"""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