Skip to content

Instantly share code, notes, and snippets.

@Mohitsharma44
Last active April 25, 2017 21:43
Show Gist options
  • Save Mohitsharma44/97080c4e3c1a8512e21786f8e2b2a977 to your computer and use it in GitHub Desktop.
Save Mohitsharma44/97080c4e3c1a8512e21786f8e2b2a977 to your computer and use it in GitHub Desktop.
sha256 for a file
import hashlib
import sys
import urllib2
import optparse
def sha256_checksum(url, block_size=65536):
filename = urllib2.urlopen(url)
sha256 = hashlib.sha256()
for block in iter(lambda: filename.read(block_size), b''):
sha256.update(block)
return sha256.hexdigest()
if __name__ == '__main__':
opt = optparse.OptionParser()
opt.add_option('--url', '-u', default='https://raw.githubusercontent.com/hk1953/ucsl-image/master/image/jupyter_config.py')
options, args = opt.parse_args()
print sha256_checksum(options.url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment