Black
This commit is contained in:
parent
1d5bc48e8e
commit
1631534f9b
2 changed files with 31 additions and 15 deletions
|
@ -1,6 +1,14 @@
|
|||
from flask import jsonify, request
|
||||
|
||||
from utils import logger, validate_data_presence, _get_weather, _get_cords, _get_date, _get_time, strq
|
||||
from utils import (
|
||||
logger,
|
||||
validate_data_presence,
|
||||
_get_weather,
|
||||
_get_cords,
|
||||
_get_date,
|
||||
_get_time,
|
||||
strq,
|
||||
)
|
||||
|
||||
# from config import
|
||||
from . import routes as app
|
||||
|
@ -11,7 +19,7 @@ from . import by_path_counter
|
|||
@by_path_counter
|
||||
def time():
|
||||
if "caller" in request.values:
|
||||
phone_number = request.values["caller"]
|
||||
phone_number = str(request.values["caller"])
|
||||
else:
|
||||
phone_number = "1"
|
||||
|
||||
|
@ -28,6 +36,7 @@ def date():
|
|||
|
||||
return strq(_get_date(phone_number))
|
||||
|
||||
|
||||
@app.route("/city", methods=["GET"])
|
||||
@by_path_counter
|
||||
def city():
|
||||
|
@ -67,7 +76,10 @@ def 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.")
|
||||
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."
|
||||
)
|
||||
|
|
10
app/utils.py
10
app/utils.py
|
@ -57,7 +57,7 @@ def validate_data_presence(data: t.Dict[str, t.Any], keys: list[str]) -> bool:
|
|||
|
||||
|
||||
def strq(str: str) -> str:
|
||||
return "\"" + str + "\""
|
||||
return '"' + str + '"'
|
||||
|
||||
|
||||
def _get_time(phone_number):
|
||||
|
@ -114,7 +114,9 @@ def _get_phone_time(phone_number):
|
|||
def _get_weather(lat, long):
|
||||
try:
|
||||
if lat is None or long is None:
|
||||
return "An error has occured and the provided zipcode could not be understood."
|
||||
return (
|
||||
"An error has occured and the provided zipcode could not be understood."
|
||||
)
|
||||
|
||||
weather_json = _get_weather_json(lat, long)
|
||||
if weather_json is None:
|
||||
|
@ -148,7 +150,9 @@ def _get_weather_json(lat, long):
|
|||
|
||||
try:
|
||||
w = Weather.query.filter(Weather.lat_long == lat_long).first()
|
||||
if w and w.last_timestamp.replace(tzinfo=timezone.utc) >= current_time - timedelta(minutes=env_CACHE_TIME):
|
||||
if w and w.last_timestamp.replace(
|
||||
tzinfo=timezone.utc
|
||||
) >= current_time - timedelta(minutes=env_CACHE_TIME):
|
||||
logger.info("Weather cache hit!")
|
||||
return w.results
|
||||
logger.info("Weather cache miss!")
|
||||
|
|
Loading…
Reference in a new issue