-
Notifications
You must be signed in to change notification settings - Fork 0
/
zach_sesonal
36 lines (30 loc) · 1.01 KB
/
zach_sesonal
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
#!/usr/bin/python3
from flask import Flask
from flask import request
with open("inseason.txt") as f:
insea = f.readlines()
insea = set(insea)
print(insea)
app = Flask(__name__)
# when the user lands at the "root" (/)
# this should return text about services available
@app.route("/")
def zindex():
return "Seasonal information is available at /inseason"
# when the user lands at "inseason" (/inseason)
# the query param "fruit" is expected
# if it is not supplied, send by an error message
# if the value associated with "fruit" does not exist
# send back "I am sorry we do not carry that item."
@app.route("/inseason")
def inseason():
if request.args.get("fruit"):
fruitq = request.args.get("fruit")
else:
return "To use this endpoint, you need to pass the query param 'fruit'"
if fruitq+"\n" in insea:
return f"Yes, {fruitq} are in season"
else:
return "I'm sorry, that item is not in season"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=2224)