def on_get(self, req, resp): """Handles GET requests""" if req.get_param('type') in ['daily', None]: data = QuoteModel.select().where( QuoteModel.created_at == datetime.date.today()) if data.exists(): data = data.get() resp.media = { 'quote': data.quote, 'author': data.author, 'category': data.category } else: quote = fetch_quote() QuoteModel.create(**quote) resp.media = quote elif req.get_param('type') == 'random': resp.media = fetch_quote() else: raise falcon.HTTPError( falcon.HTTP_400, 'Invalid Quote type', 'Supported types are \'daily\' or \'random\'.')
def on_get(self, req, resp): """Handles GET requests""" try: data = QuoteModel.select().where( QuoteModel.created_at == datetime.date.today()) if data.exists(): data = data.get() resp.media = { 'quote': data.quote, 'author': data.author, 'category': data.category } else: quote = fetch_quote() QuoteModel.create(**quote) resp.media = quote except Exception as e: raise falcon.HTTPError(falcon.HTTP_500, str(e))
def on_get(self, req, resp): """Handles GET requests""" try: resp.media = fetch_quote() except Exception as e: raise falcon.HTTPError(falcon.HTTP_500, str(e))
def set_quote_of_the_day(event, context): QuoteModel.create(**fetch_quote())
def publish_quote_of_the_day(event, context): quote = fetch_quote() async_publish(message=quote['quote'])