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\'.')
Ejemplo n.º 2
0
 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))
Ejemplo n.º 4
0
def set_quote_of_the_day(event, context):
    QuoteModel.create(**fetch_quote())
Ejemplo n.º 5
0
def publish_quote_of_the_day(event, context):
    quote = fetch_quote()
    async_publish(message=quote['quote'])