How to use the pyowm.OWM function in pyowm

To help you get started, we’ve selected a few pyowm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gchenuet / nest-datagraph / backend / poller.py View on Github external
try:
        c = configparser.ConfigParser()
        c.read(os.path.join(os.path.abspath(os.path.dirname(__file__)),
                            '../frontend/conf',
                            'settings.ini'))

        # Setup Nest account
        n = Nest(c['nest']['nest_username'],
                 c['nest']['nest_password'],
                 c['nest']['nest_sn'],
                 c['nest']['nest_index'],
                 units=c['common']['units'])
        n.login()
        n.get_status()
        # Setup OpenWeatherMap account
        owm = pyowm.OWM(c['owm']['owm_id'])
        observation = owm.weather_at_id(c['owm']['owm_city_id'])
        w = observation.get_weather()
        # Connect to DB
        cnx = mysql.connector.connect(user=c['mysql']['mysql_username'],
                                      password=c['mysql']['mysql_password'],
                                      host=c['mysql']['mysql_hostname'],
                                      database=c['mysql']['mysql_database'])
        d = cnx.cursor()
        polling(c, n, w, d)
        cnx.commit()
        d.close()
    except Exception:
        print(sys.exc_info()[1])
github home-assistant / home-assistant / homeassistant / components / weather / openweathermap.py View on Github external
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the OpenWeatherMap weather platform."""
    import pyowm

    longitude = config.get(CONF_LONGITUDE, round(hass.config.longitude, 5))
    latitude = config.get(CONF_LATITUDE, round(hass.config.latitude, 5))
    name = config.get(CONF_NAME)
    mode = config.get(CONF_MODE)

    try:
        owm = pyowm.OWM(config.get(CONF_API_KEY))
    except pyowm.exceptions.api_call_error.APICallError:
        _LOGGER.error("Error while connecting to OpenWeatherMap")
        return False

    data = WeatherData(owm, latitude, longitude, mode)

    add_entities([OpenWeatherMapWeather(
        name, data, hass.config.units.temperature_unit, mode)], True)
github dark-archerx / Traffic-Signs-and-Object-Detection / main.py View on Github external
def weather():
    lat, lan = getLatLan()
    if not lat:
        return 0, 0, 0, "- -"
    else:
        owm = pyowm.OWM('ENTER KEY HERE')
        observation = owm.weather_at_coords(lat, lan)
        w = observation.get_weather()
        tmp = w.get_temperature('celsius')
        return tmp['temp'], w.get_humidity(), w.get_wind()['speed'], w.get_status()
github directive0 / picorder / getweather.py View on Github external
def sensorget():
   sensordict = {'humidity': 0, 'temp':0, 'humidtemp':0, 'pressuretemp':0,'pressure':0,'compass':0} 

   owm = pyowm.OWM('f8c43bbd601d39c177afabec2d050d04')
   observation = owm.weather_at_place('Toronto,CA')
   w = observation.get_weather()
   temp = w.get_temperature('celsius')
   humidity = w.get_humidity()
   pressure = w.get_pressure()
   timelast = timenow
    

   sensordict['humidity'] = humidity
   sensordict['temp'] = temp['temp']
   sensordict['pressure'] = pressure['press']

   return sensordict
github MycroftAI / mycroft-core / mycroft / skills / weather / __init__.py View on Github external
def __init_owm(self):
        key = self.config.get('api_key')
        if key and not self.config.get('proxy'):
            self.owm = OWM(key)
        else:
            self.owm = OWMApi()
github aceisace / Inky-Calendar / modules / inkycal_weather.py View on Github external
"""Optional parameters"""
round_temperature = True
round_windspeed = True
use_beaufort = True
show_wind_direction = False
use_wind_direction_icon = False
now_str = 'now'


"""Set the optional parameters"""
decimal_places_temperature = None if round_temperature == True else 1
decimal_places_windspeed = None if round_windspeed == True else 1

print('Initialising weather...', end=' ')
owm = pyowm.OWM(api_key, language=language)
print('Done')

"""Icon-code to unicode dictionary for weather-font"""
weathericons = {
  '01d': '\uf00d', '02d': '\uf002', '03d': '\uf013',
  '04d': '\uf012', '09d': '\uf01a', '10d': '\uf019',
  '11d': '\uf01e', '13d': '\uf01b', '50d': '\uf014',
  '01n': '\uf02e', '02n': '\uf013', '03n': '\uf013',
  '04n': '\uf013', '09n': '\uf037', '10n': '\uf036',
  '11n': '\uf03b', '13n': '\uf038', '50n': '\uf023'
  }

"""Add a border to increase readability"""
border_top = int(top_section_height * 0.05)
border_left = int(top_section_width * 0.02)
github NaomiProject / Naomi / plugins / speechhandler / Jasperweather / jasperweather.py View on Github external
def __init__(self, *args, **kwargs):
        super(JasperWeatherplugin, self).__init__(*args, **kwargs)
        try:
            api_key = self.profile['OpenWeatherMap']['api_key']
            city_name = self.profile['OpenWeatherMap']['city_name']
            temp_unit = self.profile['country']['temp_unit']
            lang = self.profile['country']['lang']
            country = self.profile['country']['lang']
            owm = pyowm.OWM(api_key, language= lang)
        except KeyError:
            mic.say(self.gettext("Openweathermap not found in profile."))
github gil9red / SimplePyScripts / tkinter_examples / weather_example.py View on Github external
def get_weather_info(api_key, place):
    # pip install pyowm
    import pyowm
    owm = pyowm.OWM(api_key)
    observation = owm.weather_at_place(place)
    w = observation.get_weather()
    temperature = w.get_temperature('celsius')['temp']
    status = w.get_status()

    return temperature, status
github aceisace / Inky-Calendar / inkycal / modules / inkycal_weather.py View on Github external
def __init__(self, section_size, section_config):
    """Initialize inkycal_weather module"""

    super().__init__(section_size, section_config)

    # Module specific parameters
    required = ['api_key','location']
    for param in required:
      if not param in section_config:
        raise Exception('config is missing {}'.format(param))

    # module name
    self.name = self.__class__.__name__

    # module specific parameters
    self.owm = pyowm.OWM(self.config['api_key'])
    self.units = self.config['units']
    self.hour_format = self.config['hours']
    self.timezone = get_system_tz()
    self.round_temperature = True
    self.round_windspeed = True
    self.use_beaufort = True
    self.forecast_interval = 'daily' # daily # hourly
    self.locale = sys_locale()[0]
    self.weatherfont = ImageFont.truetype(fonts['weathericons-regular-webfont'],
                                          size = self.fontsize)
    # give an OK message
    print('{0} loaded'.format(self.name))