From 64d8a8eb1abeacfb431bc36c89afbcd85573c753 Mon Sep 17 00:00:00 2001 From: Evan <17254809+bigun27@users.noreply.github.com> Date: Wed, 22 Jan 2025 19:13:36 -0500 Subject: [PATCH] Add /zipcode --- app/routes/client.py | 18 ++++++++++++++++-- app/utils.py | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/routes/client.py b/app/routes/client.py index aee3269..20667af 100644 --- a/app/routes/client.py +++ b/app/routes/client.py @@ -99,7 +99,21 @@ def custom(): return str(resp) -@app.route("/test", methods=["GET", "POST"]) +@app.route("/zipcode", methods=["GET"]) +@by_path_counter +def zipcode(): + if "zipcode" in request.values: + zipcode = request.values["zipcode"] + + if len(zipcode) == 5: + weather = _get_weather(_get_cords(zipcode)) + 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 "\"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.\"" + 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.") diff --git a/app/utils.py b/app/utils.py index 1162a13..c524362 100644 --- a/app/utils.py +++ b/app/utils.py @@ -51,6 +51,9 @@ def validate_data_presence(data: t.Dict[str, t.Any], keys: list[str]) -> bool: return True +def strq(str: str) -> str: + return "\"" + str + "\"" + def _get_weather(lat, long): try: if lat is None or long is None: