import requests
from pprint import pprint

API_KEY = "0f7494fb91dbf25af5b15a3ced6e1369"

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"http://api.openweathermap.org/data/2.5/weather?{lat}&lon={lon}&limit=1&appid={API_KEY}&lang=PL&units=metric")
    pprint(response.json())


origin_city = input("Podaj nazwę miasta z którego podrożujesz: ")
destination_city = input("Podaj nazwę miasta do ktorego podrożujesz")



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)
check_coordinates(destination_city, API_KEY)
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ółżendne geograficzne to:\n{destination_lat} szerokość geograficznej /n {destination_lon} długości geograficznej")
