Optimize hot paths and reuse HTTP sessions
This commit is contained in:
@@ -7,6 +7,7 @@ import requests
|
||||
from datetime import datetime
|
||||
from ..core.config import WEATHER_LAT, WEATHER_LON, WEATHER_CITY
|
||||
|
||||
_HTTP = requests.Session()
|
||||
def get_wmo_description(code: int) -> str:
|
||||
"""Decodes WMO weather code to Russian description."""
|
||||
codes = {
|
||||
@@ -348,7 +349,7 @@ def get_coordinates_by_city(city_name: str) -> tuple:
|
||||
"format": "json"
|
||||
}
|
||||
|
||||
response = requests.get(geocode_url, params=params, timeout=10)
|
||||
response = _HTTP.get(geocode_url, params=params, timeout=10)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
@@ -403,7 +404,7 @@ def get_weather_report(requested_city: str = None) -> str:
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.get(url, params=params, timeout=10)
|
||||
response = _HTTP.get(url, params=params, timeout=10)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user