forked from tdwojak/Python2017
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
|
from weather import Weather
|
||
|
import datetime
|
||
|
|
||
|
|
||
|
def fahrenheit_to_celsius(temperature_in_fahrenheit):
|
||
|
temperature_in_celsius = (float(temperature_in_fahrenheit - 32) / (9/5))
|
||
|
return round(temperature_in_celsius, 2)
|
||
|
|
||
|
weather = Weather()
|
||
|
city = 'Poznan'
|
||
|
weather_by_location = weather.lookup_by_location(city)
|
||
|
condition = weather_by_location.condition()
|
||
|
forecasts = weather_by_location.forecast()
|
||
|
new_dict = {}
|
||
|
polish_days = ['Poniedziałek', 'Wtorek', 'Środa', 'Czwartek', 'Piątek', 'Sobota', 'Niedziela']
|
||
|
|
||
|
for forecast in forecasts:
|
||
|
data = forecast.date()
|
||
|
lowest = forecast.low()
|
||
|
new_dict.update({data: lowest})
|
||
|
min_temp_day = min(new_dict, key=new_dict.get)
|
||
|
new_date = datetime.datetime.strptime(min_temp_day, "%d %b %Y")
|
||
|
day_of_week = new_date.weekday()
|
||
|
min_temp = new_dict[min_temp_day]
|
||
|
min_temp_in_celsius = fahrenheit_to_celsius(float(min_temp))
|
||
|
|
||
|
print('Current temperature in {0}: {1} Fahrenheit. It is {2}.'.format(city, condition.temp(), condition.text().lower()))
|
||
|
|
||
|
print('Najzimniejszy dzień: {0}. Temperatura w tym dniu to {1} Celsjusza'.format(polish_days[day_of_week], min_temp_in_celsius))
|
||
|
|
||
|
|