Code Monkey home page Code Monkey logo

i3geoweather's Introduction

i3geoweather

This blocklet provides temperature information for the i3blocks status bar often used in the i3 window manager. It attempts to determine your location based on your IP address using the ipinfo.io API. Based on the location it retrieves weather information from the free openweathermap.org API.

image

i3geoweather is a pure Python 3 program. No attempt to make it compatible with Python 2 has been or will be made. It is time to switch!

Installation

The easiest way to install i3geoweather is to use pip:

$ pip install i3geoweather

Depending on your system you may need to call pip3 instead of pip

Dependencies

i3geoweather depends on the Python requests library. i3geoweather output uses FontAwesome for its output. You should download the free FontAwesome zip file and copy fontawesome-webfont.ttf to your ~/.fonts/ directory.

Usage

i3geoweather runs a daemon process in the background (if started with the -d option) and periodically updates weather information by writing to ~/.i3geoweather/i3geoweather.txt.

Start i3geoweather from your i3 configuration file:

exec_always i3geoweather -d

You may need to use the full path to i3geoweather, e.g., for an installation with pip install --user ...:

exec_always ~/.local/bin/i3geoweather -d

A typical i3blocks.conf entry may look like this:

[weather]
interval=repeat
command=inotifywait -qq -e delete_self ~/.i3geoweather/i3geoweather.txt && cat ~/.i3geoweather/i3geoweather.txt

Command line options:

  • -d or --daemon run as background process
  • -l or --location force a location by specifying a comma separated latitude/longitude pair, e.g., -l "50.0126, 7.996". North and east are positive.
  • -r or --restart restart background process
  • -s or --stop stop running background process
  • -v increase verbosity of logging to ~/.i3geoweather/i3geoweather.log. Can be used up to three times. Using -v twice logs informational messages. Debugging output is produced when -v is used three times.

Author

Jörg Dietrich [email protected]

Contributing

Development takes place on GitHub. Please report any bugs as an issue in the GitHub issue tracker.

License

i3geoweather is released under an MIT license. See LICENCE.txt

i3geoweather's People

Contributors

joergdietrich avatar

Watchers

 avatar  avatar

i3geoweather's Issues

Some Exceptions not handled correctly

2018-01-11 18:11:49,571 ERROR: error receiving weather
Traceback (most recent call last):
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/util/connection.py", line 60, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/home/joerg/applications/anaconda3/lib/python3.6/socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 357, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/home/joerg/applications/anaconda3/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/home/joerg/applications/anaconda3/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/home/joerg/applications/anaconda3/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/home/joerg/applications/anaconda3/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/home/joerg/applications/anaconda3/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 166, in connect
    conn = self._new_conn()
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 150, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f7dabbb7f28>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolu
tion

During handling of the above exception, another exception occurred:


Traceback (most recent call last):
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
    timeout=timeout
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/util/retry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='api.openweathermap.org', port=80): Max retries exceeded with url: /data/2.5/weather?lat=48.25&lon=11.65&appid=62d5bdef1ef5e
8dfccb382765b499577&units=metric (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f7dabbb7f28>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/i3geoweather/i3geoweather.py", line 139, in get_weather
    r = requests.get(weather_url, payload)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/adapters.py", line 508, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='api.openweathermap.org', port=80): Max retries exceeded with url: /data/2.5/weather?lat=48.25&lon=11.65&appid=62d5bdef1ef5e8dfccb382765b499577&units=metric (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f7dabbb7f28>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))
2018-01-11 18:17:09,691 ERROR: error receiving location
Traceback (most recent call last):
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/util/connection.py", line 60, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/home/joerg/applications/anaconda3/lib/python3.6/socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 357, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/home/joerg/applications/anaconda3/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/home/joerg/applications/anaconda3/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/home/joerg/applications/anaconda3/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/home/joerg/applications/anaconda3/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/home/joerg/applications/anaconda3/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 166, in connect
    conn = self._new_conn()
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 150, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f7dabbb7f28>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
    timeout=timeout
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/util/retry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='freegeoip.net', port=80): Max retries exceeded with url: /json/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f7dabbb7f28>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/i3geoweather/i3geoweather.py", line 108, in geolocate
    r = requests.get(geo_url)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/adapters.py", line 508, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='freegeoip.net', port=80): Max retries exceeded with url: /json/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f7dabbb7f28>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))
2018-01-11 18:17:29,714 ERROR: error receiving weather
Traceback (most recent call last):
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/util/connection.py", line 60, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/home/joerg/applications/anaconda3/lib/python3.6/socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 357, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/home/joerg/applications/anaconda3/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/home/joerg/applications/anaconda3/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/home/joerg/applications/anaconda3/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/home/joerg/applications/anaconda3/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/home/joerg/applications/anaconda3/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 166, in connect
    conn = self._new_conn()
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connection.py", line 150, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f7dabbb7c88>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
    timeout=timeout
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/urllib3/util/retry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='api.openweathermap.org', port=80): Max retries exceeded with url: /data/2.5/weather?lat=48.25&lon=11.65&appid=62d5bdef1ef5e8dfccb382765b499577&units=metric (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f7dabbb7c88>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/i3geoweather/i3geoweather.py", line 139, in get_weather
    r = requests.get(weather_url, payload)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/home/joerg/applications/anaconda3/lib/python3.6/site-packages/requests/adapters.py", line 508, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='api.openweathermap.org', port=80): Max retries exceeded with url: /data/2.5/weather?lat=48.25&lon=11.65&appid=62d5bdef1ef5e8dfccb382765b499577&units=metric (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f7dabbb7c88>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.