Esempio n. 1
0
def get_one_call():
    try:
        city = tom_forecast_city.get()
        forecast = get_weather(city)

        mgr = owm.weather_manager()
        registry = owm.city_id_registry()
        list_of_locations = registry.locations_for(city)

        location = list_of_locations[
            0]  # list of locatins - dictionary # will get allways 1'st by default
        lat = round((location.lat), 2)
        lon = round((location.lon), 2)

        one_call = mgr.one_call(lat, lon)

        tom_temp = one_call.forecast_daily[0].temperature('celsius').get(
            'feels_like_morn', None)
        tom_wi = one_call.forecast_hourly[6].wind().get('speed', 0)
        tom_hu = one_call.forecast_hourly[6].humidity

        if forecast:
            location2_lbl['text'] = (f'Feels like morning T: {tom_temp}°C.\n\
            Wind: {tom_wi} m∕s. \n\
            Humidity: {tom_hu} %')
        else:
            error_lbl['text'] = (
                f'There may be not enough info now. Please try again later')
    except:
        location2_lbl['text'] = (f'We could\'nt start your program. \n\
         Please try starting it again')
Esempio n. 2
0
def pressure_function():
	mgr = owm.weather_manager()
	observation = mgr.weather_at_place(city)
	pressure_dict = observation.weather.pressure 					# in pyOWM ---weather--- is an inbuilt method
	pressure1 = pressure_dict['press'] 								# press (atmospheric pressure on the ground in hPa)
	pressure2 = pressure_dict['sea_level'] 							# and sea_level (on the sea level, if location is on the sea | discluded from the lsit as a parameter as our locations are on the ground
	time.sleep(0.75)
	print ('...')
	print ('Current atmospheric pressure is: ' + str(pressure1) + ' bar∕mPa∕atm')
Esempio n. 3
0
def get_weather(city):  # main class

    try:
        # owm block
        mgr = owm.weather_manager()
        observation = mgr.weather_at_place(city)
        w = observation.weather

        # get_short_weather_status
        sh_status = w.status  # short version of status (eg. 'Rain')
        det_status = w.detailed_status  # detailed version of status (eg. 'light rain')

        # get_id_city
        registry = owm.city_id_registry()
        id_result = registry.ids_for(city)[0]

        # get_weather_options
        wi = w.wind()['speed']
        hu = w.humidity
        tmax = w.temperature('celsius')['temp_max']
        tmin = w.temperature('celsius')['temp_min']
        t_feel = w.temperature('celsius')['feels_like']

        # get_pressure
        pressure_dict = observation.weather.pressure  # in pyOWM ---weather--- is an inbuilt method
        pressure1 = pressure_dict[
            'press']  # press (atmospheric pressure on the ground in hPa)
        pressure2 = pressure_dict['sea_level']

        # get coords
        list_of_locations = registry.locations_for(city)
        location = list_of_locations[
            0]  # list of locatins - dictionary # will get allways 1'st by default
        lat = round((location.lat), 2)
        lon = round((location.lon), 2)

        # get sunrise & sunset
        sunrise_unix = w.sunrise_time(
        ) + 10800  #it's 10800 seconds = 3 hours # default unit: 'unix'
        sunrise_local = (pyowm.utils.formatting.timeformat(
            sunrise_unix, 'iso'))[10:-3]

        sunset_unix = w.sunset_time() + 10800  # default unit: 'unix'
        sunset_local = (pyowm.utils.formatting.timeformat(sunset_unix,
                                                          'iso'))[10:-3]

        # get rain for the last 1-12 hours (depends on meteo json response)
        rain_dict = observation.weather.rain

        final = (
            wi, hu, tmax, tmin, t_feel, pressure1, pressure2, id_result, lat,
            lon, sunrise_local, sunset_local, rain_dict, sh_status, det_status
        )  # <Weather - reference time=2013-12-18 09:20, status=Clouds>
        return (final)

    except:
        final = 'opppssssssssssssssssssssss!'
Esempio n. 4
0
def rain_function():
	try:
		mgr = owm.weather_manager()
		observation = mgr.weather_at_place(city)
		rain_dict = observation.weather.rain                               
		rr = rain_dict['1h'] # data cortege  ## it's better to select Megapolises, as their meteo works much better
		print (f'Current amount of rain fallen for the last {str(rr)[2:3]} hour: {str(rr)[-5:-1]}mm') ## shift the key in 214 from 1h to (n)h !! not all cities possess other keys than '1h'
	
	except KeyError as err:
		print ('Ooops. There is no sufficient amount of rain to determine')
Esempio n. 5
0
#__________________

city = input ('What city do U want to check the weather in?: ')

time.sleep(0.75)

#2 GET THE ID OF A CITY GIVEN IT'S NAME

registry = owm.city_id_registry()
results = registry.ids_for(city) [0]								# застосовуємо модуль списки для ідентифікації 2ого по списку міста з меню вибору (Philadelphia, PA)

print ("Selected city has the next ID: " + str(results))

#1 GET A CURRENT WEATHER STATUS OF THE CITY

mgr = owm.weather_manager()
observation = mgr.weather_at_place(city)
w = observation.weather
# print(w)                											# <Weather - reference time=2013-12-18 09:20, status=Clouds>

# Weather details
wi = w.wind() ['speed']                 							# {'speed': 4.6, 'deg': 330}
hu = w.humidity                										# 87
t = w.temperature('celsius') ['temp'] 								# {'temp_max': 10.5, 'temp': 9.7, 'temp_min': 9.0, 'feels_like': 22,68 }

print ("In the city of " + city + ", we have the next weather conditions: " + "Wind speed - " + str(wi) + " km∕h" + ", relative humidity - " + str(hu) + "% " + ", T - " + str(t) + " °C")

#_______PAUSE______
time.sleep(0.75)
print ('...')
#__________________