Coder Social home page Coder Social logo

aquatix / ns-notifications Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 123 KB

Get notified when your NS (Dutch Railways) train is delayed, or makes a quick transfer which normally you wouldn't catch possible

License: MIT License

Python 95.47% Shell 4.53%

ns-notifications's Introduction

ns-notifications

Get notified when your NS (Dutch Railways) train is delayed, or makes a quick transfer which normally you wouldn't catch possible. Makes use of the ns-api library.

Installation

Clone this project to your local drive:

git clone https://github.com/aquatix/ns-notifications.git

nsapi is now in PyPI! You can now simply install it through pip and it's included in requirements.txt.

First check if you use a version of Python that's at least 2.7.9: python --version. If not, go to the "Python <2.7.9" section first!

Create a new virtualenv (mkvirtualenv is a command when you have virtualenvwrapper installed - you can do so with sudo apt-get install virtualenvwrapper) and install the dependencies:

mkvirtualenv ns-notifications   # only if you didn't do so already
pip install -r requirements.txt

Also, memcached itself has to be running (e.g., apt-get install memcached; ns-notifications assumes port 11211).

Then copy settings_example.py to settings.py and modify the configuration to your needs. You might want to check what id your desired device has in the Pushbullet list. If an invalid id is provided, ns_notifications.py will provide you with a list of your devices with their corresponding id's.

N.B.: if you encounter issues after updating from the repo, try checking settings_example.py against your settings.py. Some new configuration items might be added.

Upgrading

If you got a notification that ns-notifier needs upgrading, you can run ./run_notifier upgrade. This will do a git pull and other necessary updates. Updating ns-api can't be done (yet) through this method though. To upgrade, just do a git pull in its directory.

Python <2.7.9

If you run an older version of Python (for example Ubuntu 14.04 LTS ships with 2.7.6), the requests library needs a more secure version of the ssl sub system.

On Ubuntu, first install some SSL and Python header files and then install the requests extension:

mkvirtualenv ns-notifications   # if you didn't do so already
sudo apt-get install python-dev libffi-dev libssl-dev
pip install 'requests[security]'

Now continue with the steps above, starting from the line with requirements.txt.

NS API key

To actually be able to query the Nederlandse Spoorwegen API, you need to request a key. Provide a good reason and you will likely get it mailed to you (it might take some days).

After receiving the key, put it together with the email address you used in settings.py.

Running

ns_notifications.py is best called through a crontab entry. The run_notifier script is provided for convenience, as it enables the virtualenv for you (assuming the name 'ns-notifications' and virtualenvwrapper installed for the workon command). For example:

# Call every five minutes from 7 to 10 and then from 16 to 18 hours:
*/5  7-9  * * 1-5 cd /home/username/bin/crontab/ns-notifications; ./run_notifier
*/5 16-17 * * 1-5 cd /home/username/bin/crontab/ns-notifications; ./run_notifier

It can be disabled by setting the nsapi_run tuple in memcache to False.

Screenshot

PushBullet notifications

Web frontend

server.py has been included to provide a web interface. You can just run that file and it will enable a simple website to be available on your server at port 8086.

After creating the ns-notifications virtualenv, you will have to install the requirements for the server (type workon ns-notifications if you don't have the environment enabled):

pip install -r requirements_server.txt

Now you can run the server by starting the run_server script. It will open a small web server on port 8086 of your machine, which you can make GET requests on to check for the status (just the root document, so for example http://example.com:8086/), to disable notifications for a bit (/disable/) or enable them (/enable/). The keyword variable here is intended to be replaced by a location for example, which really is just for your convenience (for example when you use Tasker, you can have it do a request on http://example.com:8086/disable/work when you arrive at work, but you can put whatever text you like in there).

ns-notifications's People

Contributors

aquatix avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

reyhard

ns-notifications's Issues

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.