diff options
| author | Aaron LI <aaronly.me@gmail.com> | 2016-01-06 15:11:44 +0800 | 
|---|---|---|
| committer | Aaron LI <aaronly.me@gmail.com> | 2016-01-06 15:11:44 +0800 | 
| commit | dba767e8ff1599a0b4cf8fb3dc06ac0cce727748 (patch) | |
| tree | 1c85bbf6409e1cb398da0dcb4cd5ad8a78644354 /.i3/py3status/backup/weather_yahoo.py | |
| parent | c07a9bd96fde28c0f672af8d1b4d345c2e34f1b3 (diff) | |
| download | dotfiles-dba767e8ff1599a0b4cf8fb3dc06ac0cce727748.tar.bz2 | |
i3: update configuration for i3wm
* Update i3 wm config
* Add i3blocks.conf
* Remove py3status
Diffstat (limited to '.i3/py3status/backup/weather_yahoo.py')
| -rw-r--r-- | .i3/py3status/backup/weather_yahoo.py | 106 | 
1 files changed, 0 insertions, 106 deletions
diff --git a/.i3/py3status/backup/weather_yahoo.py b/.i3/py3status/backup/weather_yahoo.py deleted file mode 100644 index 6b91b04..0000000 --- a/.i3/py3status/backup/weather_yahoo.py +++ /dev/null @@ -1,106 +0,0 @@ -# -*- coding: utf-8 -*- -from time import time -import requests - - -class Py3status: -    """ -    Display current day + 3 days weather forecast as icons on your i3bar -    Based on Yahoo! Weather. forecast, thanks guys ! -    See: http://developer.yahoo.com/weather/ -    """ -    def __init__(self): -        """ -        Basic configuration -        Find your city code using: -            http://answers.yahoo.com/question/index?qid=20091216132708AAf7o0g -        The city_code in this example is for Paris, France -        """ -        self.cache_timeout = 1800 -        self.city_code = 'FRXX0076' -        self.request_timeout = 10 - -    def _get_forecast(self): -        """ -        Ask Yahoo! Weather. for a forecast -        """ -        r = requests.get( -            'http://query.yahooapis.com/v1/public/yql?q=select item from weather.forecast where location="%s"&format=json' % self.city_code, -            timeout=self.request_timeout -        ) - -        result = r.json() -        status = r.status_code -        forecasts = [] - -        if status == 200: -            forecasts = result['query']['results']['channel']['item']['forecast'] -            # reset today -            forecasts[0] = result['query']['results']['channel']['item']['condition'] -        else: -            raise Exception('got status {}'.format(status)) - -        # return current today + 3 days forecast -        return forecasts[:4] - -    def _get_icon(self, forecast): -        """ -        Return an unicode icon based on the forecast code and text -        See: http://developer.yahoo.com/weather/#codes -        """ -        icons = ['☀', '☁', '☂', '☃', '?'] -        code = int(forecast['code']) -        text = forecast['text'].lower() - -        # sun -        if 'sun' in text or code in [31, 32, 33, 34, 36]: -            code = 0 - -        # cloud / early rain -        elif 'cloud' in text or code in [ -                19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, -                44 -                ]: -            code = 1 - -        # rain -        elif 'rain' in text or code in [ -                0, 1, 2, 3, 4, 5, 6, 9, -                11, 12, -                37, 38, 39, -                40, 45, 47 -                ]: -            code = 2 - -        # snow -        elif 'snow' in text or code in [ -                7, 8, -                10, 13, 14, 15, 16, 17, 18, -                35, -                41, 42, 43, 46 -                ]: -            code = 3 - -        # dunno -        else: -            code = -1 - -        return icons[code] - -    def weather_yahoo(self, json, i3status_config): -        """ -        This method gets executed by py3status -        """ -        response = { -            'cached_until': time() + self.cache_timeout, -            'full_text': '', -            'name': 'weather_yahoo' -            } - -        forecasts = self._get_forecast() -        for forecast in forecasts: -            icon = self._get_icon(forecast) -            response['full_text'] += '{} '.format(icon) -        response['full_text'] = response['full_text'].strip() - -        return (0, response)  | 
