-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
48 lines (40 loc) · 1.26 KB
/
app.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
45
46
47
48
from flask import Flask, request, jsonify, render_template
import pandas as pd
import random
import requests
app = Flask(__name__)
@app.route('/a/', methods=['GET'])
def allQuotes():
response = {}
data = pd.read_csv('data/quotes.csv')
data = data.to_dict()
speakers = data.get("speaker")
quotes = data.get("quote")
# quotes data
qd = {speakers.get(i):quotes.get(i) for i in range(len(speakers))}
response["Quotes"] = qd
response["Code"] = 200
return jsonify(response)
@app.route('/r/', methods=['GET'])
def randomQuote():
response = {}
data = pd.read_csv('data/quotes.csv')
data = data.to_dict()
speaker = data.get('speaker')
quote = data.get('quote')
index = random.randint(0,len(speaker) - 1)
response["Speaker"] = speaker.get(index)
response["Quote"] = quote.get(index)
response["Code"] = 200
return jsonify(response)
@app.route('/')
def index():
rand_quote = requests.get('https://parks-and-rec-quotes.herokuapp.com/r').json()
q = rand_quote.get("Quote")
s = rand_quote.get("Speaker")
return render_template('index.html', quote=q, speaker=s)
@app.route('/api')
def api_info():
return render_template('api-info.html')
if __name__ == '__main__':
app.run(threaded=True, port=5000)