diff --git a/handler.py b/handler.py index baa1475..e011eb4 100755 --- a/handler.py +++ b/handler.py @@ -1,7 +1,8 @@ -from flask import render_template +from flask import Flask, render_template from qusasat import Qusasat import base64 +app = Flask(__name__) # Load data qusasat = Qusasat(categories_file='./data/categories.csv', quotes_file='./data/qusasat.csv') # Load the only image we have as base64 data in memory @@ -11,9 +12,10 @@ base64_string = base64_data.decode('utf-8') def run(event, context): - global qusasat, base64_string + global app, qusasat, base64_string quote = qusasat.get_random_quote() - return render_template('quote.html', - category=quote['category'], - quote=quote['quote'], - background_image_url=f'data:image/png;base64,{base64_string}') + with app.app_context(): + return render_template('quote.html', + category=quote['category'], + quote=quote['quote'], + background_image_url=f'data:image/png;base64,{base64_string}')