Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. # [START app]
  2. import logging
  3. import os
  4.  
  5. from google.cloud import storage
  6. from google.appengine.api import app_identity
  7.  
  8. # [START imports]
  9. from flask import Flask, render_template, request
  10. # [END imports]
  11.  
  12.  
  13. app = Flask(__name__)
  14.  
  15. BUCKET = 'simplebird'
  16.  
  17. def download_output(output_bucket, filename):
  18. """Downloads the output file from Cloud Storage and returns it as a
  19. string."""
  20. print('Downloading output file')
  21. client = storage.Client()
  22. bucket = client.get_bucket(output_bucket)
  23. output_blob = (
  24. 'keys/{}'
  25. .format(filename))
  26. return bucket.blob(output_blob).download_as_string()
  27.  
  28. # [START home]
  29. @app.route('/')
  30. def home():
  31. return '<h1>Home!</h1>'
  32. # [END home]
  33.  
  34. # [START test]
  35. @app.route('/test')
  36. def test():
  37. return download_output(BUCKET, 'mailchimp_api.encrypted')
  38. # [END test]
  39.  
  40.  
  41. @app.errorhandler(500)
  42. def server_error(e):
  43. # Log the error and stacktrace.
  44. logging.exception('An error occurred during a request.')
  45. return 'An internal error occurred.', 500
  46. # [END app]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement