73 lines
2 KiB
Python
73 lines
2 KiB
Python
from flask import jsonify, request
|
|
|
|
from utils import logger, validate_data_presence, _get_weather, _get_cords, _get_date, _get_time, strq
|
|
|
|
# from config import
|
|
from . import routes as app
|
|
from . import by_path_counter
|
|
|
|
|
|
@app.route("/time", methods=["GET"])
|
|
@by_path_counter
|
|
def time():
|
|
if "caller" in request.values:
|
|
phone_number = request.values["caller"]
|
|
else:
|
|
phone_number = "1"
|
|
|
|
return strq(_get_time(phone_number))
|
|
|
|
|
|
@app.route("/date", methods=["GET"])
|
|
@by_path_counter
|
|
def date():
|
|
if "caller" in request.values:
|
|
phone_number = request.values["caller"]
|
|
else:
|
|
phone_number = 1
|
|
|
|
return strq(_get_date(phone_number))
|
|
|
|
@app.route("/city", methods=["GET"])
|
|
@by_path_counter
|
|
def city():
|
|
if "city" in request.values:
|
|
city = request.values["city"]
|
|
# Return a different message depending on the caller's choice
|
|
# Asheboro
|
|
if city == "1":
|
|
weather = _get_weather(35.6396, -79.8509)
|
|
return strq(weather)
|
|
# Lynchburg
|
|
elif city == "2":
|
|
weather = _get_weather(37.3490, -79.1787)
|
|
return strq(weather)
|
|
# Cullowhee
|
|
elif city == "3":
|
|
weather = _get_weather(35.3087, -83.1861)
|
|
return strq(weather)
|
|
else:
|
|
return strq("Your selection is invalid.")
|
|
else:
|
|
return strq("A city is required.")
|
|
|
|
|
|
@app.route("/zipcode", methods=["GET"])
|
|
@by_path_counter
|
|
def zipcode():
|
|
if "zipcode" in request.values:
|
|
zipcode = request.values["zipcode"]
|
|
|
|
if len(zipcode) == 5:
|
|
lat, long = _get_cords(zipcode)
|
|
weather = _get_weather(lat, long)
|
|
return strq(weather)
|
|
else:
|
|
return strq("Sorry, I don't understand that zipcode.")
|
|
else:
|
|
return strq("A zipcode is required.")
|
|
|
|
@app.route("/test", methods=["GET"])
|
|
@by_path_counter
|
|
def test():
|
|
return strq("Successful test. By the way, do you know the muffin man? The muffin man? The muffin man? Do you know the muffin man? He doesn't exist.")
|