import requests
from pprint import pprint

API_KEY = "7759d8230b94a48172ae2b1d52b5024e"

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}&lang=PL&units=metric")
    response_json = response.json()
    weather = response_json['weather'][0]['description']
    temperature = response_json['main']['temp']
    pressure = response_json['main']['pressure']
    humidity = response_json['main']['pressure']

    return weather, temperature, pressure, humidity

print("Witaj jestem Travelinventor, twój inteligentny inacej asystent podróży")
origin_city = input("Podaj miasto z którego podróżujesz")
destination_city = input("Podaj miasto docelowe: ")
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"Miasto z którego podróżujesz: {origin_city}")
print(f"Miasto do którego podróżujesz: {destination_city}")
print(f"Jego współrzędne geograficzne: \n{destination_lat} szerokości geograficznej \n{destination_lon} długości geograficznej")
print(f"Pogoda : {weather}")
print(f"Temperatura {temperature} st.Celcjusza")
print(f"wilgotność: {humidity}%")
print(f"ciśnienie atmosferyczne {pressure}hPa")