import requests
from pprint import pprint

API_KEY = "d3ccbb460a4ec460f02ae3b6040b3e97"

def check_coordinates(city, API_KEY):
    url = f"http://api.openweathermap.org/geo/1.0/direct?q={city}&limit=1&appid={API_KEY}"
    response = requests.get(url)
    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, API_KEY):
    url = f"https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={API_KEY}&lang=PL&units=metric"
    response = requests.get(url)
    print(response.status_code)
    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/v3.1/alpha/{country_code.upper()}"
    response = requests.get(url)
    country_name = response.json()[0]['name']['common']
    return country_code

print("Hej jestem Travelinator i pomoge ci w czyms tam")
origin_city = input("Podaj miasto z ktorego podrozujesz")
destination_city = input("Podaj miasto do ktorego podrozujesz")

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)

print(f"Miasto z ktorego podrozujesz: {origin_city}")
print(f"Miasto do ktorego podrozujesz: {destination_city}")
print(f"Jego współrzędne geograficzne to: \n {destination_lat} szerokosci \n {destination_lon} długości geograficznej")

weather, temperature, pressure, humidity = get_weather_info(destination_lat, destination_lon, API_KEY)

print(f"Pogoda: {weather}")
print(f"Temperatura: {temperature} st. Celcjusza")
print(f"Ciśnienie {pressure} hPa")
print(f"Wilgotność: {humidity}%")