Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # [START app]
- import logging
- import os
- from google.cloud import storage
- from google.appengine.api import app_identity
- # [START imports]
- from flask import Flask, render_template, request
- # [END imports]
- app = Flask(__name__)
- BUCKET = 'simplebird'
- def download_output(output_bucket, filename):
- """Downloads the output file from Cloud Storage and returns it as a
- string."""
- print('Downloading output file')
- client = storage.Client()
- bucket = client.get_bucket(output_bucket)
- output_blob = (
- 'keys/{}'
- .format(filename))
- return bucket.blob(output_blob).download_as_string()
- # [START home]
- @app.route('/')
- def home():
- return '<h1>Home!</h1>'
- # [END home]
- # [START test]
- @app.route('/test')
- def test():
- return download_output(BUCKET, 'mailchimp_api.encrypted')
- # [END test]
- @app.errorhandler(500)
- def server_error(e):
- # Log the error and stacktrace.
- logging.exception('An error occurred during a request.')
- return 'An internal error occurred.', 500
- # [END app]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement