import requests
from pprint import pprint

API_KEY = "16ae68028cbbf0ff90fb61b4d70b967d"

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}&limit=1&appid={API_KEY}&lang=PL&units=metric')
    #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']
    wind_speed = response_json['wind']['speed']
    return weather, temperature, pressure, humidity, wind_speed
def get_courrecy_code(country_code):
    response = requests.get(f"https://api.restcountries.com/countries/v5/code?q={country_code.upper()}",headers={'Authorization': 'Bearer rc_live_71989fd6f43341e28c21808ec07516a9'})
    pprint(response.json())
    currency_code = response.json()['data']['objects'][0]['currencies'][0]['code']
    print(currency_code)

    return currency_code

print("Witaj, jestem Travelinator, twój inteligentny asystent podróży")
origin_city = input("Podaj nazwę miasta z którego podróżujesz: ")
destitanion_city = input("Podaj nazwę miasta do którego podróżujesz: ")

origin_lat, origin_lon, origin_city, origin_country = check_coordinates(origin_city,API_KEY)
destitanion_lat, destitanion_lon, destitanion_city,destitanion_country = check_coordinates(destitanion_city,API_KEY)

weather, temperature, pressure, humidity, wind_speed =get_weather_info(destitanion_lat,destitanion_lon)

ori_curr = get_courrecy_code(origin_country)
des_curr = get_courrecy_code(destitanion_country)

print(f"Miasto z którego podróżujesz: {origin_city}")
print(f"Miasto do którego podróżujesz: {destitanion_city}")
print(f"Jego współrzędne geograficzne to:\n{destitanion_lat} szerokości geograficznej \n{destitanion_lon} dlugości geograficznej")
print(f"Pogoda : {weather}")
print(f"Temperatura {temperature} st.Celcjusza")
print(f"wilgotność: {humidity}%")
print(f"ciśnienie atmosferyczne {pressure}hPa")
print(f"prędkość wiatru {wind_speed}km/h")
