-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdemodec4.py
55 lines (47 loc) · 1.44 KB
/
demodec4.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
49
50
51
52
53
54
from flask import Flask
from flask import jsonify
from time import gmtime, strftime
import pandas as pd
import wikipedia
from textblob import TextBlob
app = Flask(__name__)
@app.route('/')
def hello():
"""Return a friendly HTTP greeting."""
return 'Hello World December 4th!'
@app.route('/name/<value>')
def name(value):
print(f"This value was passed into a URL: /name/{value}")
if value == "bear":
val = {"mammal": value}
else:
val = {"unknown": value}
return jsonify(val)
@app.route('/time')
def time():
my_time = strftime("%Y-%m-%d %H:%M:%S", gmtime())
print(f"This was the time I returned")
my_time_dict = {"time": my_time}
return jsonify(my_time_dict)
@app.route('/html')
def html():
"""Returns some custom HTML"""
return """
<title>This is a Hello World World Page</title>
<p>Hello: It is December 4th, 2019</p>
<p><b>World</b></p>
"""
@app.route('/pandas')
def pandas_sugar():
df = pd.read_csv("https://raw.githubusercontent.com/noahgift/sugar/master/data/education_sugar_cdc_2003.csv")
return jsonify(df.to_dict())
@app.route('/wikipedia/<company>')
def wikipedia_route(company):
result = wikipedia.summary(company, sentences=10)
res = TextBlob(result)
val = {"company": company,
"summary": result,
"polarity": res.sentiment.polarity}
return jsonify(val)
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)