0% found this document useful (0 votes)
26 views3 pages

Project Code

The document outlines a Python-based AI weather assistant that predicts activities based on current weather conditions. It includes a sample training dataset with temperature, humidity, wind speed, and corresponding activity suggestions. The assistant fetches real-time weather data using an API and provides tailored activity recommendations based on the fetched conditions.

Uploaded by

223317
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Project Code

The document outlines a Python-based AI weather assistant that predicts activities based on current weather conditions. It includes a sample training dataset with temperature, humidity, wind speed, and corresponding activity suggestions. The assistant fetches real-time weather data using an API and provides tailored activity recommendations based on the fetched conditions.

Uploaded by

223317
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

# 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)

You might also like