import requests
from pprint import pprint

API_KEY = "8c5bef75167c5c155354b31af01b4162"

def check_coordinates(city, API_KEY):
    response = requests.get(f"http://api.openweathermap.org/geo/1.0/direct?q={city}&appid={API_KEY}")
    print(response.status_code)
    pprint(response.json())
    lat = response.json()[0]['lat']
    lon = response.json()[0]['lon']
    city = response.json()[0]['name']
    country = response.json()[0]['country']

    return lat, lon, city, country

def get_weather_info(lat,lon):
    response=requests.get(f"https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={API_KEY}")
    print(response.status_code)
    pprint(response.json())
    response_json = response.json()
    weather = response_json["weather"][0]['description']
    temperature = response_json["main"]["temp"]
    pressure = response_json["main"]["pressure"]
    humidity = response_json["main"]["humidity"]

    return weather, temperature, pressure, humidity

def get_country_full_name(country_code):
    url = f"https://restcountries.com/{country_code.upper()}"

print("I am your AI assistent 🤯")
origin_city = input("Type in the City name which you are going from: ")
destination_city = input("Type in you City destination: ")

origin_lat, origin_lon, origin_city, origin_country = check_coordinates(origin_city, API_KEY)
destination_lat, destination_lon, destination_city, destination_country = check_coordinates(destination_city, API_KEY)
weather, temperature, pressure, humidity = get_weather_info(destination_lat, destination_lon)

print(f"Begining City: {origin_city}")
print(f"End Destination (City): {destination_city}")
print(f"""Jego wspolrzedne geograficzne to:\n
      {destination_lat} szerokosci geograficznej:\n
        {destination_lon} dlugosci geograficznej""")
print(f"Weather: {weather}")
print(f"Temperature: {temperature} st. Celsjusza")
print(f"Wilgotność {humidity}%")
print(f"Ciśnienie ")



