Skip to content

Instantly share code, notes, and snippets.

@joelhsmith
Last active February 7, 2019 17:25
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 joelhsmith/bb65ee44b0d2c96c71c978350838c522 to your computer and use it in GitHub Desktop.
Save joelhsmith/bb65ee44b0d2c96c71c978350838c522 to your computer and use it in GitHub Desktop.
Creates a hash of a remote file, like a PDF
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