Skip to content

Commit

Permalink
Merge pull request snarfed#17 from kevinmarks/master
Browse files Browse the repository at this point in the history
replace printing with progress bars
  • Loading branch information
snarfed committed Apr 2, 2016
2 parents 3b2154d + 8c03ae1 commit 72708e6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ def run():
<!DOCTYPE html>
<html>
<head><title>huffduff-video: %s</title></head>
<style> #progress span {display:none;}
#progress span:last-of-type {display:inline;}
</style>
<script type="text/javascript">
window.setInterval(function() { window.scrollTo(0, document.body.scrollHeight); }, 500);
</script>
<body>
<h1>huffduff-video</h1>
<div id="progress">
Fetching %s ...<br />""" % (url, url)).encode('utf-8')

# function to print out status while downloading
Expand All @@ -75,12 +79,12 @@ def download_progress_hook(progress):
return
elif status == 'downloading':
p = lambda field: progress.get(field) or ''
msg = '%s of %s at %s in %s...' % (
msg = '<span><progress max="100" value="%s"></progress> of %s at %s in %s...</span>' % (
p('_percent_str'), p('_total_bytes_str') or p('_total_bytes_estimate_str'),
p('_speed_str'), p('_eta_str'))
else:
msg = status
write(msg + '<br />\n')
msg = status+ '<br />\n'
write(msg)

# fetch video info (resolves URL) to see if we've already downloaded it
options = {
Expand Down Expand Up @@ -132,7 +136,7 @@ def download_progress_hook(progress):
yield 'Uploading to S3...<br />\n'

def upload_callback(sent, total):
write('%s%%...<br />\n' % (sent * 100 / total))
write('<span><progress max="100" value="%s"></progress> </span>\n' % (sent * 100 / total))

key.set_contents_from_filename(filename, cb=upload_callback)
key.make_public()
Expand Down

0 comments on commit 72708e6

Please sign in to comment.