Push notifications from Python to Phone using pushover

If something strange happens on your server or in your python-app you may want to send a push notification. I chose pushover for this.

Create an app here: https://pushover.net/apps/build.

Your usertoken is on your dashboard mainpage in pushover.

The script needs requests.

import requests
import sys

r = requests.post("https://api.pushover.net/1/messages.json",
                  data={'token': 'APP_TOKEN',
                        'user': 'USER_KEY',
                        'message': u' '.join(sys.argv[1:])})

This can now be called for example like this:

python pushover.py This is my message!

I use this on error in cronjobs for private projects.

Running TensorFlow with Python 3 kernel in Docker on RaspberryPI

Installing docker on Raspberry PI 3


Docker image for TensorFlow with Python 3 kernel

Based on the tensorflow-rpi-Python2 image (https://github.com/philipz/rpi-tensorflow) of philipz I made some changes and updated to TensorFlow 0.9.

Code: https://github.com/mfa/rpi-tensorflow

Image: https://hub.docker.com/r/mfandreas/rpi-tensorflow-python3/

Running TensorFlow

With Docker installed on the Raspberry PI running TensorFlow is this easy:

docker run -d -p 8888:8888 mfandreas/rpi-tensorflow-python3

Now hit your browser to


Using shotwell to label images

I needed to label a lot of images into 4 classes. Using the ratings of shotwell this can be really fast.

Pressing 1 to 5 to set a rating on an image.


The next step was to get the ratings for later use as labels in machine learning.

Because shotwell stores its data in a sqlite database we only need some lines of Python to get the labels:

import csv
import os.path
import sqlite3
import sys

# location of shotwell sqlite file
db_file = os.path.join(os.environ.get("HOME"), '.local/share/shotwell', 'data', 'photo.db')
conn = sqlite3.connect(db_file)
c = conn.cursor()
rows = c.execute('SELECT filename, rating FROM phototable WHERE rating > 0 ORDER BY filename;')
csvwriter = csv.writer(sys.stdout, delimiter=';')
csvwriter.writerow(["filename", "rating"])
for (filename, rating) in rows:
    csvwriter.writerow([os.path.basename(filename), rating])

Only the ratings bigger than 0 are selected. The CSV is written to stdout by default.