import requests
from pprint import pprint

API_KEY = "972f3d36602ffe9b74c5a4dcc9124b93"

def sprawdz_koordynaty(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

print('Witaj, jestem aplikacja do sprawdzania pogody na swiecie...')
origin_city = input('Podaj nazwe miasta z ktorego podrozujesz ')
destination_city = input('Podaj nazwe miasta do ktorego podrozujesz ')

def get_weather_info(lat, lon):
    response = requests.get(f'https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&limit=1&appid={API_KEY}&lang=PL&units=metric')
    print(response.status_code)
    pprint(response.json())
    weather = response.json()['weather'][0]['description']
    temp = response.json()['main']['temp']
    pressure = response.json()['main']['pressure']
    humidity = response.json()['main']['humidity']
    return weather, temp, pressure, humidity

def get_country_full_info(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_name

def get_currency_code(country_code):
    url = f"https://restcountries.com/v3.1/alpha/{country_code.upper()}"
    response = requests.get(url)
    currency_code = list(response.json()[0]['currencies'].keys())[0]
    return currency_code

origin_lat, origin_lon, origin_city, origin_country = sprawdz_koordynaty(origin_city, API_KEY)

destination_lat, destination_lon, destination_city, destination_country = sprawdz_koordynaty(destination_city, API_KEY)

weather, temp, pressure, humidity = get_weather_info(destination_lat, destination_lon)

ori_curr = get_currency_code(origin_country)
dest_curr = get_currency_code(destination_country)

print(f'Miasto z ktorego podrozujesz: {origin_city}')
print(f'Lezy w kraju {get_country_full_info(origin_country)}')
print(f'Waluta w tym miescie to {ori_curr}')
print(f'Miasto do ktorego podrozujesz: {destination_city}')
print(f'Lezy w kraju {get_country_full_info(destination_country)}')
print(f'Waluta w tym miescie to {dest_curr}')
print(f'Jego wspolrzedne geograficzne to: \n{destination_lat} szerokości geograficznej,\n{destination_lon} dlugosci geograficznej')
print(f'Pogoda: {weather}')
print(f'Temperatura: {temp} st. Celsjusza')
print(f'Wilgotnosc: {humidity}')
print(f'Cisnienie: {pressure}hPa')