import requests

# OpenWeatherMap API key
owm_api_key = 'API_key'
owm_url = f'http://api.openweathermap.org/data/2.5/weather?q=Bangalore,IN&appid={owm_api_key}&units=metric'
# Gemini API key
gemini_api_key = 'API_key'
gemini_url = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=' + gemini_api_key


# Get weather data from OpenWeatherMap
owm_response = requests.get(owm_url)
if owm_response.status_code == 200:
    owm_data = owm_response.json()
    temperature = owm_data['main']['temp']
    humidity = owm_data['main']['humidity']
    condition = owm_data['weather'][0]['description']
    weather_info = f'Temperature: {temperature}°C, Humidity: {humidity}%, Condition: {condition}'
else:
    print("Failed to get weather data from OpenWeatherMap:", owm_response.status_code, owm_response.text)
    weather_info = "Unable to retrieve weather data."


headers = {
    'Content-Type': 'application/json'
}

data = {
    "contents": [
        {
            "parts": [
                {"text": f"You're a humorous AI robot. Describe this weather in a hilarous way. Your answer should be between 50 to 60 characters. Respond with only the humorous sentence and nothing else.: {weather_info}"}
            ]
        }
    ]
}

# Get summary from Gemini API
gemini_response = requests.post(gemini_url, headers=headers, json=data)
if gemini_response.status_code == 200:
    gemini_summary = gemini_response.json()['candidates'][0]['content']['parts'][0]['text']
    print(gemini_summary)
else:
    print("Failed to get response from Gemini API:", gemini_response.status_code, gemini_response.text)
