#454 Endpoint life-decision
Merged 4 years ago by gnaponie. Opened 4 years ago by gnaponie.
gnaponie/greenwave life-decision  into  master

file modified
+36
@@ -2,6 +2,7 @@ 

  

  import logging

  import datetime

+ import random

  from flask import Blueprint, request, current_app, jsonify, url_for, redirect, Response

  from werkzeug.exceptions import BadRequest, NotFound, UnsupportedMediaType

  from prometheus_client import generate_latest
@@ -563,3 +564,38 @@ 

  @api.route('/metrics', methods=['GET'])

  def metrics():

      return Response(generate_latest(registry))

+ 

+ 

+ @api.route('/life-decision', methods=['GET'])

+ @jsonp

+ def life_decision():

+     # Ask a question and Greenwave gives you an advice for your

+     # life decisions.

+     data = request.args

+     if not data or not data.get('question'):

+         return 'You need to ask me a question. Use the "question" parameter to ask me something'

+     RESPONSES = [

+         'If you take a step on every stone you find, you\'ll never arrive in Rome.',

+         'Keep on doing what you do with passion, and you\'ll never regret it.',

+         'Look inside yourself and you\'ll find the answer that you are looking for.',

+         'A smile will gain you ten more years of life.',

+         'A bird does not sing because it has an answer. It sings because it has a song.',

+         'Be not afraid of growing slowly, be afraid only of standing still.',

+         'Patience is a bitter plant, but its fruit is sweet.',

+         'Whatever you\'ll decide to do, is going to be a success if it is your own decision.',

+         'Never regret your own decision, better to follow your heart, than follow a fool.',

+         'I see great things in your future.',

+         'Why are you asking me, if you already know the answer?',

+         'I know you already know the answer.',

+         'Whatever will happen, face it with a smile.',

+         'I will always be here, ready to reply when you\'ll need me.',

+         'Good things will happen to you.',

+         'If you fail, try again.',

+         'I don\'t understand this questions.',

+         'That\'s a good question. Are you really sure you should ask it to me?.',

+         'If you want to find out about the road ahead, then ask about it from those coming back.',

+         'Small people think they are small, great people never know they are great.',

+         'If you are patient in one moment of anger, you will escape a hundred days of sorrow.',

+         'Ask Jan Kaluza, he will know it.',

+     ]

+     return random.choice(RESPONSES)

@@ -90,3 +90,14 @@ 

      assert 200 == response.status_code

      assert '1 of 1 required test results missing' == response.json['summary']

      mock_waivers.assert_called_once()

+ 

+ 

+ def test_life_decision():

+     app = create_app('greenwave.config.TestingConfig')

+     client = app.test_client()

+     data = {

+         'question': 'Where am I going to be in 5 years?'

+     }

+     response = client.get('/api/v1.0/life-decision', json=data)

+     assert response.status_code == 200

+     assert type(response.data.decode("utf-8")) == str

Ask a question to Greenwave checking the /life-decision endpoint,
it will give you an advice for your life. Greenwave is just a service,
it cannot give you every answers for your life decisions, but it can
help you to find the answer inside your heart.

Signed-off-by: gnaponie gnaponie@redhat.com

rebased onto 9cc9828ea91ccabfad830719cd59413b96193203

4 years ago

rebased onto a47da8b0be06a2eea6f0bfb25d9ed927694d7021

4 years ago

1 new commit added

  • torebase
4 years ago

rebased onto 0a3de43ddb843adc63b5dbce95d3f37e2fc3a6c9

4 years ago

rebased onto f0587cc

4 years ago

Pull-Request has been merged by gnaponie

4 years ago

@gnaponie where's the documentation for this API endpoint?

@mprahl we were not sure if doc would be appropriate too. Is it supposed to be hidden? Dunno. Opinions?

@mprahl we were not sure if doc would be appropriate too. Is it supposed to be hidden? Dunno. Opinions?

How will I know that Greenwave can give me such good advice then? :stuck_out_tongue:

Haha, love it! :confetti_ball: