Last active
February 7, 2019 17:25
-
-
Save joelhsmith/bb65ee44b0d2c96c71c978350838c522 to your computer and use it in GitHub Desktop.
Creates a hash of a remote file, like a PDF
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 os, hashlib, optparse, requests | |
def get_remote_sha_sum(url): | |
'''put remote file in memory and create hash''' | |
response = requests.get(url) | |
try: | |
response.raise_for_status() | |
sha1 = hashlib.sha1() | |
response = response.content | |
sha1.update(response) | |
return sha1.hexdigest() | |
except requests.exceptions.HTTPError as e: | |
return "Error: " + str(e) | |
if __name__ == '__main__': | |
opt = optparse.OptionParser() | |
opt.add_option('--url', '-u', default='https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf') | |
options, args = opt.parse_args() | |
print get_remote_sha_sum(options.url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment