Weather

Detailed weather plugin powered by DarkSky with auto location lookup. Supports metric and imperial units. Needs API key from https://darksky.net/dev/.

Image preview of Weather plugin.

weather.15m.py

Edit
Open on GitHub
#!/usr/bin/python
# -*- coding: utf-8 -*-

# <xbar.title>Weather</xbar.title>
# <xbar.version>v3.5.0</xbar.version>
# <xbar.author>Daniel Seripap</xbar.author>
# <xbar.author.github>seripap</xbar.author.github>
# <xbar.desc>Detailed weather plugin powered by DarkSky with auto location lookup. Supports metric and imperial units. Needs API key from https://darksky.net/dev/.</xbar.desc>
# <xbar.image>https://cloud.githubusercontent.com/assets/683200/16276583/ff267f36-387c-11e6-9fd0-fc57b459e967.png</xbar.image>
# <xbar.dependencies>python</xbar.dependencies>


# -----------------------------------------------------------------------------------
# For a more accurate location lookup, download and install CoreLocationCLI
# Available here: https://github.com/fulldecent/corelocationcli/releases
# This will allow a more precise location lookup as it uses native API for loc lookup
# -----------------------------------------------------------------------------------

import json
import urllib2
import textwrap
from random import randint
import commands

# get yours at https://darksky.net/dev
api_key = ''

# get yours API key for encode location at https://opencagedata.com
geo_api_key = ''

# if you want to set manual location, define following two vars. If left empty, script will try to determine the location
# example:
# manual_city = 'Novi Sad'
# manual_latlng = '45.2526331,19.7817785'
manual_city = ''
manual_latlng = ''


# set to si for metric, leave blank for imperial
units = ''

# optional, see message above
core_location_cli_path = '~/CoreLocationCLI'

def manual_location_lookup():
  if manual_latlng == "" or manual_city == "":
     return False;
  else:
     return { "loc": manual_latlng, "preformatted": manual_city }

def mac_location_lookup():
  try:
    exit_code, loc = commands.getstatusoutput(core_location_cli_path + ' -once -format "%latitude,%longitude"')
    if exit_code != 0:
      raise ValueError('CoreLocationCLI not found')
    formatted_city_name = reverse_latlong_lookup(loc)
    return { "loc": loc, "preformatted": formatted_city_name }
  except:
    return False

def auto_loc_lookup():
  try:
    location = urllib2.urlopen('https://ipinfo.io/json')
    return json.load(location)
  except urllib2.URLError:
    return False

def reverse_latlong_lookup(loc):
  try:
    location_url = 'https://api.opencagedata.com/geocode/v1/json?q=' + loc + '&key=' + geo_api_key + '&language=en&no_annotations=1&pretty=1'
    location = json.load(urllib2.urlopen(location_url))
    if 'results' in location:
      return location['results'][0]['formatted'].encode('UTF-8')
    else:
      return 'Could not lookup location name'
  except:
    return 'Could not lookup location name'

def full_country_name(country):
  try:
    countries = json.load(urllib2.urlopen('http://country.io/names.json'))
    try:
      if country in countries:
        return countries[country].encode('UTF-8')
      else:
        return False
    except KeyError:
      return False
  except urllib2.URLError:
    return False

def calculate_bearing(degree):
  cardinals = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']
  return cardinals[int(round(((6 * degree)) / 360))]

def get_wx_icon(icon_code):
  if icon_code == 'clear-day':
    icon = 'iVBORw0KGgoAAAANSUhEUgAAAFYAAABaCAQAAACInWkHAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAARt4AAEbeAY4mMlsAAAAHdElNRQfkAwQTLi3Ze1bDAAAAEGNhTnYAAADMAAAAzAAAADsAAAA5A2zbKAAABe9JREFUaN7tm9tvFFUcxz/bbrf30JaU5QUptUUuFQhye4KEKBYBjUEwIbE2Bh4khBdjoFpJFDCENiFcXgyRKj7iA4kJ4B8gPBgBoTW0DS1tua29LWx3trS7HV/OTme3O925nFnF7G8fdqdzzu989rtnZn7n9zsF2VbNbQIEuE21bNde6bC5VDIPiJIr23WOdFgXLQubhc3CZmGzsP8e7FZ2Z/jL5LCbrXY6bqefYRrxWOxXyyNUVB5Ra7Gnh0aG6We7VdRt9KGiMmQZ1y6sh0aGUFHpY1vqJkaBzEIqAZhLC/AjqulBVRQigGKhD3j4mBbmAlDJQktfEx+HCKPaULeQDWxiExsotKGqSphD+KzBgo/DGu6gjblr3jw0MqihHraOCpBnW12rqHpV8+w6cl9dKarGzaq6HoqpwI+fCopNtLakarplzSSn8PAVRcTvDBeZStGuiI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Pa4s+13InJdk5wyLfbdjBNgnlM9bJZTOxR5QBLO/d2hdsdFFgphj0WmGOckvZXoqdTprvGU9UJ4x5kdhjzEHCHMac+Fq/6m2tDk+yuUecs7VtmWnJbufZa5qEOQRyQn4HMNbl9FnZxmiiXNrvfsfbZ5xSQzhbDRzYra1U4XV1othJfbejVgf0O/r6GGG+goBfao8r4y8y21Q0/3mihPvRkesPAQkQe51VcVCDPcYnX7+rm5cnVVrKjFxZ0ik5JPdo3bD2EsHuVG5cmp7L0f5p7pfHOTewGL/cBAnbIqlaO/G8xPLkG8bXyW5TpMvU32XjLa3zPNpY47wAlYnlIX+7kVyQe93gP6HWrT7bvidoqrjUsa3+0DS7xtpTU2q1UndFaoRF+DneKT+iU/qsJzfmHBoV9iax80OQb7sjFObppLGtXYqc5uobOuihU0DYJaS73gjxa1LzTUXui9KvEpI51mkF7yM1yuqLHVKq/7h/kdEUzuGOi9KtbPYAOcoI9uiuSotcMHViu3zJrmZ4Ht0f8AtlrKz5jSaW8AAAAldEVYdGRhdGU6Y3JlYXRlADIwMjAtMDMtMDRUMTk6NDY6MzIrMDA6MDDFtlJNAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDIwLTAzLTA0VDE5OjQ2OjMyKzAwOjAwtOvq8QAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAAASUVORK5CYII='
  else:
    icon = ''

  return icon

def get_wx():

  if api_key == "":
    return False

  location = manual_location_lookup() or mac_location_lookup() or auto_loc_lookup()

  if location is False:
    return False

  for locData in location:
    locData.encode('utf-8')

  try:
    if 'loc' in location:
      wx = json.load(urllib2.urlopen('https://api.darksky.net/forecast/' + api_key + '/' + location['loc'] + '?units=' + units + "&v=" + str(randint(0,100))))
    else:
      return False
  except urllib2.HTTPError:
    return False

  if units == 'si':
    unit = 'C'
    distance = 'm/s'
    distance_short = 'km'
  else:
    unit = 'F'
    distance = 'mph'
    distance_short = 'mi'

  try:

    weather_data = {}

    if 'currently' in wx:
      for item in wx['currently']:
        if item == 'temperature':
          weather_data['temperature'] = str(int(round(wx['currently']['temperature']))) + '°' + unit
        elif item == 'icon':
          weather_data['icon'] = get_wx_icon(str(wx['currently']['icon']))
        elif item == 'summary':
          weather_data['condition'] = str(wx['currently']['summary'].encode('utf-8'))
        elif item == 'windSpeed':
          weather_data['wind'] = str(wx['currently']['windSpeed']) + ' ' + distance
        elif item == 'windBearing':
          weather_data['windBearing'] = calculate_bearing(wx['currently']['windBearing'])
        elif item == 'humidity':
          weather_data['humidity'] = str(int(round(wx['currently']['humidity'] * 100))) + '%'
        elif item == 'dewPoint':
          weather_data['dewPoint'] = str(wx['currently']['dewPoint'])
        elif item == 'visibility':
          weather_data['visibility'] = str(int(round(wx['currently']['visibility']))) + ' ' + distance_short
        elif item == 'pressure':
          weather_data['pressure'] = str(wx['currently']['pressure']) + ' mb'
        elif item == 'apparentTemperature':
          weather_data['feels_like'] = str(int(round(wx['currently']['apparentTemperature']))) + '°' + unit

    if 'minutely' in wx:
      for item in wx['minutely']:
        if item == 'summary':
          weather_data['next_hour'] = str((wx['minutely']['summary'].encode('utf-8')))

    if 'daily' in wx:
      for item in wx['daily']:
        if item == 'summary':
          weather_data['week'] = str((wx['daily']['summary'].encode('utf-8', 'ignore')))

    if 'city' in location and 'region' in location:
      if location['city'] == '' and location['region'] == '':
        if 'country' in location:
            country = full_country_name(location['country'])

            if country is False or location['country'] == '':
              weather_data['country'] = 'See Full Forecast'
            else:
              weather_data['country'] = country
      else:
        weather_data['city'] = str(location['city'].encode('utf-8'))
        weather_data['region'] = str(location['region'].encode('utf-8'))

    if 'loc' in location:
      weather_data['loc'] = str(location['loc'])

    if 'preformatted' in location:
      weather_data['preformatted'] = location['preformatted']

  except KeyError:
    return False

  return weather_data

def render_wx():

  if api_key == '':
    print 'Missing API key'
    print '---'
    print 'Get an API Key | href=https://darksky.net/dev'
    return False

  weather_data = get_wx()

  if weather_data is False:
    print '--'
    print '---'
    print 'Could not get weather data at this time'
    return False

  if 'icon' in weather_data and 'temperature' in weather_data:
    print weather_data['temperature'] + ' | templateImage=' + weather_data['icon']
  else:
    print 'N/A'

  print '---'


  if 'city' in weather_data and 'region' in weather_data:
    print weather_data['city'] + ', ' + weather_data['region'] + ' | href=https://darksky.net/' + weather_data['loc']
  elif 'country' in weather_data:
    print weather_data['country'] + ' | href=https://darksky.net/' + weather_data['loc']
  elif 'preformatted' in weather_data:
    print weather_data['preformatted'] + ' | href=https://darksky.net/' + weather_data['loc']

  if 'condition' in weather_data and 'feels_like' in weather_data:
    print weather_data['condition'] + ', Feels Like: ' + weather_data['feels_like']

  print '---'

  if 'next_hour' in weather_data:
    print weather_data['next_hour']
    print '---'

  print '---'

  if 'week' in weather_data:
    print "\n".join(textwrap.wrap(weather_data['week'], 50))
    print '---'

  if 'wind' in weather_data and 'windBearing' in weather_data:
    print 'Wind: ' + weather_data['wind'] + ' ' + weather_data['windBearing']

  if 'humidity' in weather_data:
    print 'Humidity: ' + weather_data['humidity']

  if 'dewPoint' in weather_data:
    print 'Dew Point: ' + weather_data['dewPoint']

  if 'visibility' in weather_data:
    print 'Visibility: ' + weather_data['visibility']

  if 'pressure' in weather_data:
    print 'Pressure: ' + weather_data['pressure']

  print '---'
  print 'Powered by DarkSky | href=https://darksky.net/poweredby/?ref=bitbarWeather'

render_wx()