Example #1
0
    def __init__(self, bot: commands.Bot):
        super(Weather, self).__init__(bot, __file__)

        owm_config = get_default_config_for_subscription_type(
            Config.weather_openweather_sub_type)
        self.owm = OWM(Config.weather_openweather_api_key, owm_config)
        self.weather_manager = self.owm.weather_manager()

        self.forecast_api_usage = 0
        self.forecast_api_usage_lock = threading.Lock()
Example #2
0
 def __init__(self, language):
     # Language must be 2-char code 'en' or 'de'
     if language is None:
         language = translation.default_language
     cfg = config.load_configuration(config.HELHEIMR_CONFIG_FILE_FORECAST)
     owm_cfg = get_default_config_for_subscription_type('free')
     owm_cfg['language'] = language.lower()
     self._owm = OWM(cfg.openweathermap.api_token, owm_cfg)
     self._latitude = cfg.openweathermap.latitude
     self._longitude = cfg.openweathermap.longitude
     self._mgr = self._owm.weather_manager()
     self._language = language
Example #3
0
 def test_get_default_config_for_subscription_type(self):
     result = config.get_default_config_for_subscription_type('free')
     self.assertEqual(SubscriptionTypeEnum.FREE,
                      result['subscription_type'])
     result = config.get_default_config_for_subscription_type('startup')
     self.assertEqual(SubscriptionTypeEnum.STARTUP,
                      result['subscription_type'])
     result = config.get_default_config_for_subscription_type('developer')
     self.assertEqual(SubscriptionTypeEnum.DEVELOPER,
                      result['subscription_type'])
     result = config.get_default_config_for_subscription_type(
         'professional')
     self.assertEqual(SubscriptionTypeEnum.PROFESSIONAL,
                      result['subscription_type'])
     result = config.get_default_config_for_subscription_type('enterprise')
     self.assertEqual(SubscriptionTypeEnum.ENTERPRISE,
                      result['subscription_type'])
     with self.assertRaises(ValueError):
         config.get_default_config_for_subscription_type('non-existent')
Example #4
0
from time import timezone
from pyowm import OWM
from pyowm.utils import config
from pyowm.utils.config import get_config_from
from pyowm.utils import timestamps

config_dict = config.get_default_config_for_subscription_type('professional')
owm = OWM('ввести код полученный на сайте https://openweathermap.org/',
          config_dict)
owm.supported_languages
config_dict['language'] = 'ru'
mgr = owm.weather_manager()
#place = input("Ваше местоположение(city, country): ")

observation = mgr.weather_at_place('Vitebsk, BY')

reg = owm.city_id_registry()
list_of_locations = reg.locations_for('Vitebsk', country='BY')
vitebsk = list_of_locations[0]
lat = vitebsk.lat
lon = vitebsk.lon

#daily_forecast = mgr.forecast_at_place('Vitebsk,BY', 'daily').forecast

w = observation.weather

print(f'Витебск. Долгота: {lat} Широта: {lon}')
#print(w.temperature('celsius'), w.detailed_status, w.wind(), w.rain, w.clouds, w.humidity, w. heat_index)
print('Сейчас: ' + str(w.detailed_status))
print('Температура: ' + str(w.temperature('celsius')))
#print('Ощущается: ' + str(w. heat_index))
Example #5
0
from pyowm.owm import OWM
from pyowm.utils.config import get_config_from
from pyowm.utils.config import get_default_config_for_subscription_type
from pyowm.utils import timestamps, formatting

config_dict = get_default_config_for_subscription_type('free')
owm = OWM('1a8b1d6e34be977e469e42517727e81b', config_dict)

owm.supported_languages

config_dict = owm.configuration

version_tuple = (major, minor, patch) = owm.version

reg = owm.city_id_registry()
#list_of_tuples = munich = reg.ids_for('Munich', country='DE')                 # only one: [ (2643743,, 'London, GB') ]
#list_of_tuples = reg.ids_for('london', country='GB', matching='like')           # mehrere Einträge mit bes. string im Namen
#id_of_london_city = list_of_tuples[0][0]

list_of_locations = reg.locations_for('munich', country='DE')
munich = list_of_locations[0]  # IDs als Liste
lat = munich.lat  # Längengrad München
lon = munich.lon  # Breitengrad München

print("city: " + str(list_of_locations))

#print(id_of_london_city)
#print (list_of_tuples[0:5])
#print(lat, lon)

mgr = owm.weather_manager()
Example #6
0
import json

from datetime import datetime, timedelta

from config import OWM_TOKEN, SUBSCRIPTION_TYPE
from app.plot_utils import make_plot
from app.clothing_rec import temp_rec, condition_rec

from pyowm.owm import OWM
from pyowm.utils.config import get_default_config_for_subscription_type

from app.utils import to_celsius, prep_location_str, format_time

owm_config_dict = get_default_config_for_subscription_type(SUBSCRIPTION_TYPE)
owm = OWM(OWM_TOKEN, owm_config_dict)
mgr = owm.weather_manager()
reg = owm.city_id_registry()

with open("app/cn2cc.json", "r") as cn2cc:
    cn2cc = json.load(cn2cc)


class WeatherWrapper:
    def __init__(self, lat=None, lon=None, location=None, scale='celsius'):
        if location is not None:
            self.location = location
            if ',' in self.location:
                self.city, self.country = [
                    prep_location_str(loc) for loc in self.location.split(',')
                ]