2025-01-20 20:09:02 -05:00
|
|
|
from flask import jsonify, request
|
|
|
|
|
2025-01-28 20:29:51 -05:00
|
|
|
from utils import (
|
|
|
|
logger,
|
|
|
|
validate_data_presence,
|
|
|
|
_get_weather,
|
|
|
|
_get_cords,
|
|
|
|
_get_date,
|
|
|
|
_get_time,
|
|
|
|
strq,
|
|
|
|
)
|
2025-01-20 20:09:02 -05:00
|
|
|
|
|
|
|
# from config import
|
|
|
|
from . import routes as app
|
|
|
|
from . import by_path_counter
|
2025-01-20 23:15:24 -05:00
|
|
|
|
|
|
|
|
2025-01-26 20:55:14 -05:00
|
|
|
@app.route("/time", methods=["GET"])
|
|
|
|
@by_path_counter
|
|
|
|
def time():
|
|
|
|
if "caller" in request.values:
|
2025-01-28 20:29:51 -05:00
|
|
|
phone_number = str(request.values["caller"])
|
2025-01-26 20:55:14 -05:00
|
|
|
else:
|
|
|
|
phone_number = "1"
|
2025-01-28 20:29:51 -05:00
|
|
|
|
2025-01-26 20:55:14 -05:00
|
|
|
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
|
2025-01-28 20:29:51 -05:00
|
|
|
|
2025-01-26 20:55:14 -05:00
|
|
|
return strq(_get_date(phone_number))
|
|
|
|
|
2025-01-28 20:29:51 -05:00
|
|
|
|
2025-01-22 21:32:12 -05:00
|
|
|
@app.route("/city", methods=["GET"])
|
|
|
|
@by_path_counter
|
|
|
|
def city():
|
|
|
|
if "city" in request.values:
|
|
|
|
city = request.values["city"]
|
2025-01-28 21:24:21 -05:00
|
|
|
if "day" in request.values:
|
|
|
|
day = int(request.values["day"])
|
|
|
|
if day < 0 or day > 7:
|
|
|
|
return strq("Your day selection is invalid.")
|
|
|
|
else:
|
|
|
|
day = 0
|
2025-01-22 21:32:12 -05:00
|
|
|
# Return a different message depending on the caller's choice
|
|
|
|
# Asheboro
|
|
|
|
if city == "1":
|
2025-01-28 21:24:21 -05:00
|
|
|
weather = _get_weather(day, 35.6396, -79.8509)
|
2025-01-22 21:32:12 -05:00
|
|
|
return strq(weather)
|
|
|
|
# Lynchburg
|
|
|
|
elif city == "2":
|
2025-01-28 21:24:21 -05:00
|
|
|
weather = _get_weather(day, 37.3490, -79.1787)
|
2025-01-22 21:32:12 -05:00
|
|
|
return strq(weather)
|
|
|
|
# Cullowhee
|
|
|
|
elif city == "3":
|
2025-01-28 21:24:21 -05:00
|
|
|
weather = _get_weather(day, 35.3087, -83.1861)
|
2025-01-22 21:32:12 -05:00
|
|
|
return strq(weather)
|
|
|
|
else:
|
2025-01-28 21:24:21 -05:00
|
|
|
return strq("Your city selection is invalid.")
|
2025-01-22 21:32:12 -05:00
|
|
|
else:
|
|
|
|
return strq("A city is required.")
|
|
|
|
|
|
|
|
|
2025-01-22 19:13:36 -05:00
|
|
|
@app.route("/zipcode", methods=["GET"])
|
|
|
|
@by_path_counter
|
|
|
|
def zipcode():
|
|
|
|
if "zipcode" in request.values:
|
|
|
|
zipcode = request.values["zipcode"]
|
2025-01-28 21:24:21 -05:00
|
|
|
if "day" in request.values:
|
|
|
|
day = int(request.values["day"])
|
|
|
|
if day < 0 or day > 7:
|
|
|
|
return strq("Your day selection is invalid.")
|
|
|
|
else:
|
|
|
|
day = 0
|
2025-01-22 19:13:36 -05:00
|
|
|
if len(zipcode) == 5:
|
2025-01-22 19:42:00 -05:00
|
|
|
lat, long = _get_cords(zipcode)
|
2025-01-28 21:24:21 -05:00
|
|
|
weather = _get_weather(day, lat, long)
|
2025-01-22 19:13:36 -05:00
|
|
|
return strq(weather)
|
|
|
|
else:
|
|
|
|
return strq("Sorry, I don't understand that zipcode.")
|
|
|
|
else:
|
|
|
|
return strq("A zipcode is required.")
|
|
|
|
|
2025-01-28 20:29:51 -05:00
|
|
|
|
2025-01-22 19:13:36 -05:00
|
|
|
@app.route("/test", methods=["GET"])
|
2025-01-22 18:11:25 -05:00
|
|
|
@by_path_counter
|
|
|
|
def test():
|
2025-01-28 20:29:51 -05:00
|
|
|
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."
|
|
|
|
)
|