Skip to content

Instantly share code, notes, and snippets.

@misodengaku
Last active March 27, 2018 16:45
Show Gist options
  • Save misodengaku/5d5f6581a78be43bfaa7daa05b088ba8 to your computer and use it in GitHub Desktop.
Save misodengaku/5d5f6581a78be43bfaa7daa05b088ba8 to your computer and use it in GitHub Desktop.
import hashlib
import urllib.request
import os
if not os.path.isdir('NIKON'):
os.makedirs('NIKON')
if os.path.exists('NIKON/NML_28A.ee'):
with open('NIKON/NML_28A.ee', 'rb') as f:
checksum = hashlib.sha1(f.read()).hexdigest()
print("Old file: %s" % checksum)
else:
checksum = 'invalid'
with urllib.request.urlopen('http://crossgate.nikonimglib.com/dsd_redirect/redirect.do?P=F9JnZ07&R=SLOnf25&L=uTmf400&O=CVMiG00') as response:
newfile = response.read()
newhash = hashlib.sha1(newfile).hexdigest()
print("New file: %s" % newhash)
if checksum == newhash:
print("already up to date")
exit(0)
with open('NIKON/NML_28A.ee', 'wb') as f:
f.write(newfile)
with open('NIKON/NML_28A.ee', 'rb') as f:
checksum = hashlib.sha1(f.read()).hexdigest()
print("Updated: %s" % checksum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment