# Open a new zip file for writing zip = zipfile.ZipFile(ZIP_FILE, 'w') for filename, url in IMAGES: # Download each image and save to tmp directory urllib.urlretrieve(url, filename) # Add each image to the zip file zip.write(filename) # Close the zip file for writing zip.close() # Set the headers to force download of the file http_header("Content-Type", "application/octet-stream") http_header("Content-Disposition", "attachment;filename=%s" % ZIP_FILE) # Return zip file content base64 encoded # Note that the file is opened in binary read mode (rb) dump_message({ "content": base64.encodestring(open(ZIP_FILE, 'rb').read()), "message_type": "console", "encoding": "base64" }) # Download images # Add images to zip file # Download zip file import urllib
# # Test to handle query string params # from scraperwiki.utils import httpresponseheader as http_header from scraperwiki.utils import GET as query_string # Get query string parameters qs = query_string() # Download file if value submitted if 'id' in qs: http_header("Content-Type", "application/octet-stream") http_header("Content-Disposition", "attachment; filename=file.txt") print "Hello world" print "Your id is %s" % qs['id'] else: # Form to submit value print """ <form> <p><input type="text" name="id"/></p> <p><input type="submit" value="Download File"></p> </form> """# # Test to handle query string params #
# # Test to handle query string params # from scraperwiki.utils import httpresponseheader as http_header from scraperwiki.utils import GET as query_string # Get query string parameters qs = query_string() # Download file if value submitted if 'id' in qs: http_header("Content-Type", "application/octet-stream") http_header("Content-Disposition", "attachment; filename=file.txt") print "Hello world" print "Your id is %s" % qs['id'] else: # Form to submit value print """ <form> <p><input type="text" name="id"/></p> <p><input type="submit" value="Download File"></p> </form> """# # Test to handle query string params # from scraperwiki.utils import httpresponseheader as http_header from scraperwiki.utils import GET as query_string
for filename, url in IMAGES: # Download each image and save to tmp directory urllib.urlretrieve(url, filename) # Add each image to the zip file zip.write(filename) # Close the zip file for writing zip.close() # Set the headers to force download of the file http_header("Content-Type", "application/octet-stream") http_header("Content-Disposition", "attachment;filename=%s" % ZIP_FILE) # Return zip file content base64 encoded # Note that the file is opened in binary read mode (rb) dump_message({"content":base64.encodestring(open(ZIP_FILE, 'rb').read()), "message_type":"console", "encoding":"base64"}) # Download images