Created
March 16, 2015 12:09
-
-
Save lwis/a49bb775c28ac36136d0 to your computer and use it in GitHub Desktop.
Download and generate digests for all links in content
This file contains hidden or 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
| import hashlib, re, urllib | |
| resources = """<text with links in goes here>""" | |
| def hashfile(afile, hasher, blocksize=65536): | |
| buf = afile.read(blocksize) | |
| while len(buf) > 0: | |
| hasher.update(buf) | |
| buf = afile.read(blocksize) | |
| return hasher.hexdigest() | |
| urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', resources) | |
| for url in urls: | |
| fileurl, headers = urllib.urlretrieve(url) | |
| print url | |
| print hashfile(open(fileurl, 'rb'), hashlib.sha256()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment