-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
44 lines (29 loc) · 1.14 KB
/
main.py
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
43
44
from typing import Tuple, Any
from flask import Flask, send_from_directory
import random
import os
import json
app = Flask(__name__)
with open('quotes/long_quotes.json', 'r', encoding='utf-8') as f:
long_quotes = json.load(f)
with open('quotes/short_quotes.json', 'r', encoding='utf-8') as f:
short_quotes = json.load(f)
@app.route("/shortquote", methods=["GET"])
def short_quote() -> tuple[Any, int]:
return random.choice(short_quotes), 200
@app.route("/longquote", methods=["GET"])
def long_quote() -> tuple[Any, int]:
return random.choice(long_quotes), 200
@app.route("/quote", methods=["GET"])
def any_quote() -> tuple[Any, int]:
quote_file = random.choice([short_quotes, long_quotes])
return random.choice(quote_file), 200
@app.route("/", methods=["GET"])
def index():
return "<html><h1>ORV Quote API</h1><p>This API provides a random quote from ORV.</p></html>", 200
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'assets'),
'favicon.ico', mimetype='image/vnd.microsoft.icon')
if __name__ == '__main__':
app.run(debug=False)