fixed weather timeouts
This commit is contained in:
10
main.py
10
main.py
@@ -54,7 +54,13 @@ def send_sms(number, message):
|
|||||||
print("📤 SEND:", r.text)
|
print("📤 SEND:", r.text)
|
||||||
|
|
||||||
def get_weather(city):
|
def get_weather(city):
|
||||||
r = session.get(f"https://wttr.in/{city}?format=j1", timeout=5)
|
try:
|
||||||
|
r = session.get(
|
||||||
|
f"https://wttr.in/{city}?format=j1",
|
||||||
|
timeout=4 # keep it under 5s total budget
|
||||||
|
)
|
||||||
|
except requests.exceptions.RequestException:
|
||||||
|
return f"⚠️ Weather service timeout for {city}. Try again later."
|
||||||
|
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
return f"❌ Weather unavailable for {city}"
|
return f"❌ Weather unavailable for {city}"
|
||||||
@@ -75,6 +81,8 @@ def get_weather(city):
|
|||||||
|
|
||||||
return msg.strip()
|
return msg.strip()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def load_state():
|
def load_state():
|
||||||
if not STATE_FILE.exists():
|
if not STATE_FILE.exists():
|
||||||
return {"seen_offsets": []}
|
return {"seen_offsets": []}
|
||||||
|
|||||||
Reference in New Issue
Block a user