-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
42 lines (35 loc) · 858 Bytes
/
api.py
File metadata and controls
42 lines (35 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
Julius Caesar API
This API generates quotes from the very famous Roman emperor, Caesar.
Author: Ciro Goyeneche
"""
import random
import dotenv
from flask import Flask, request, jsonify
from utils import get_quotes_from_file
# Load .env config
dotenv.load_dotenv()
app = Flask(__name__)
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
@app.route('/')
def index():
info = {
"message": 'Welcome to Caesar API',
"actions": [
'GET /quote'
]
}
return jsonify(info)
@app.route('/quote')
def quote():
# Get quotes from file
quotes = get_quotes_from_file('static/quotes.txt')
# Randomly choose a quote from the list
quote = random.choice(quotes)
response = {
"quote": quote,
"message": 'success'
}
return jsonify(response)
if __name__ == "__main__":
app.run()