# PURE PYTHON AI-BASED WEATHER ASSISTANT
import requests
# --- Sample Training Dataset ---
# [temperature, humidity, wind speed, condition, suggestion]
training_data = [
[90, 75, 10, "sunny", "Stay indoors and drink water"],
[70, 50, 5, "clear", "Go for a walk or picnic"],
[60, 90, 15, "rain", "Carry an umbrella"],
[85, 60, 5, "sunny", "Enjoy outdoor games"],
[55, 80, 20, "storm", "Avoid going outside"],
[45, 60, 30, "windy", "Stay safe from strong winds"],
[80, 85, 10, "cloudy", "Good for a jog"],
[72, 65, 12, "sunny", "Ideal for light exercise"],
# --- Simple AI Predictor Function ---
def predict_activity(temp, humidity, wind, condition):
best_match = None
smallest_diff = float('inf')
for row in training_data:
t, h, w, cond, label = row
# Check if condition keyword matches
if cond in condition.lower():
diff = abs(temp - t) + abs(humidity - h) + abs(wind - w)
if diff < smallest_diff:
smallest_diff = diff
best_match = label
return best_match or "No suggestion found. Try again later."
# --- Weather Fetching Function ---
def get_weather(city, api_key):
url = f"https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/
timeline/{city}?unitGroup=us&key={api_key}&contentType=json"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
current = data['currentConditions']
temp = current['temp']
humidity = current['humidity']
wind = current['windspeed']
condition = current['conditions']
print(f"\nWeather for: {data['resolvedAddress']}")
print(f"Temperature: {temp} °F")
print(f"Condition: {condition}")
print(f"Humidity: {humidity}%")
print(f"Wind Speed: {wind} mph")
# AI Suggestion
suggestion = predict_activity(temp, humidity, wind, condition)
print(f"\nAI Suggestion: {suggestion}")
else:
print("Failed to retrieve weather data")
# --- Run the Assistant ---
city = input("Enter city name: ")
api_key = "XGFFA33ZH2MEWVASUQP8JMJRK"
get_weather(city, api_key)