Skip to content

Instantly share code, notes, and snippets.

@agalera
Created May 22, 2016 18:54
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 agalera/fb8b097e13e08528d6a530150cea965c to your computer and use it in GitHub Desktop.
Save agalera/fb8b097e13e08528d6a530150cea965c to your computer and use it in GitHub Desktop.
launcher ld48-desmadrestudio
import urllib2
import hashlib
import os
import json
download_base = "http://desmadrestudio.com/static/ld48/"
# obtain find images/* -exec md5sum {} +
j = urllib2.urlopen(download_base + 'update.json')
j_obj = json.load(j)
list_download = j_obj['files']
print "create dir"
try:
os.makedirs('ld48-desmadrestudio')
except:
pass
def download_file(url):
file_name = url.split('/')[-1]
for x in range(len(url.split('/')) - 1):
temp = ""
if (os.path.exists('ld48-desmadrestudio/' + url.split('/')[x]) == False):
temp += url.split('/')[x]
if temp != "":
print "create dir"
os.makedirs('ld48-desmadrestudio/' + temp)
u = urllib2.urlopen(download_base + url)
f = open(str('ld48-desmadrestudio/' + url), 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (file_name, file_size),
file_size_dl = 0
block_sz = 8192
md5 = hashlib.md5()
while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += len(buffer)
f.write(buffer)
md5.update(buffer)
status = r"[%3.2f%%]" % (file_size_dl * 100. / file_size)
status = status + chr(8) * (len(status) + 1)
print status,
f.close()
return md5.hexdigest()
def md5_for_file(url_file):
md5 = hashlib.md5()
with open(str(url_file), 'rb') as f:
for chunk in iter(lambda: f.read(8192), b''):
md5.update(chunk)
return md5.hexdigest()
for actual_download in list_download:
try:
tmp_md5 = md5_for_file('ld48-desmadrestudio/' + actual_download['url'])
except:
tmp_md5 = "error"
if actual_download['md5'] != tmp_md5:
while True:
if actual_download['md5'] == download_file(actual_download['url']):
actual_download['value'] = True
break
else:
print "error download, try again"
print "\n"
else:
print "md5 ok"
os.system('cd ld48-desmadrestudio & start.exe')
{
"files": [
{
"url": "assets/background.png",
"md5": "e5e1c6f0fff11065beca32a9bc47b4c4",
"value": false
},
{
"url": "assets/bullet.png",
"md5": "651d5e1194400d9859f081e4dbbafa08",
"value": false
},
{
"url": "start.exe",
"md5": "dac2fed89c34528e383ad066c746e513",
"value": false
}
],
"boolean": true,
"null": null,
"number": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment