Aaayushiii commited on
Commit
9983157
·
verified ·
1 Parent(s): cd9d141

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -12
app.py CHANGED
@@ -59,18 +59,8 @@ def get_weather(location: str) -> str | None:
59
  import requests
60
 
61
  def extract_location(text: str) -> str | None:
62
- """
63
- Use Open-Meteo geocoding to detect if a location exists in the query.
64
- Works for lowercase, uppercase, and misspellings (fuzzy matching).
65
- """
66
- try:
67
- url = f"https://geocoding-api.open-meteo.com/v1/search?name={text}&count=1&language=en&format=json"
68
- r = requests.get(url, timeout=5).json()
69
- if r.get("results"):
70
- return r["results"][0]["name"]
71
- except:
72
- pass
73
- return None
74
 
75
 
76
 
 
59
  import requests
60
 
61
  def extract_location(text: str) -> str | None:
62
+ caps = re.findall(r"\b([A-Z][a-z]+(?:\s+[A-Z][a-z]+)*)\b", text)
63
+ return max(caps, key=len) if caps else None
 
 
 
 
 
 
 
 
 
 
64
 
65
 
66