Category Archives: python

Un petit script python qui m’envoie des mails quand le RER est malade

Un petit script tout moche python qui m’envoie des mails quand le RER est malade, lancé avec une crontab aux horaires qui m’intéressent, et voilà!

# -*- coding: utf-8 -*-

import time
now = time.ctime()

# RATP API part
## c'est la partie magique, merci Pierre!
import requests
r = requests.get("")
data = r.text

import json
parsed_json = json.loads(data)
if parsed_json["trafic"] == "perturbation":
  mailbody = parsed_json["perturbations"]

  ## mail part
  import subprocess
  import smtplib
  import email.utils
  from email.mime.text import MIMEText

  recipients = ","
  # Create the message
  msg = MIMEText(str(mailbody))
  msg['To'] = recipients
  msg['From'] = ""
  msg['Subject'] = "RERB status -- " + now

  server = smtplib.SMTP('')
  log = server.set_debuglevel(True) # show communication with the server
      server.sendmail(msg["From"], msg["To"].split(","), msg.as_string())

automating #Twitter with #raspberrypi

I’ve been tweeting pictures and re-tweeting twits automatically for a few years now using two python tools.

  1. Twython
  2. on github
    Here’s an example script for Twython

  3. TwitterFollowBot
  4. on github
    Here’s an example script for TwitterFollowBot

Both require to have an already created Twitter app ( and a little bit of python.

Temperature and humidity graph with raspberry pi

Top posted update:
Now it looks like this

  • a pinch of pygal
  • 1 raspberry pi (I used model B)
  • breadboard + accessories
  • DHT22 (or equivalent)

I just followed Adafruit’s tutorial for the wiring and the software
Then I did a slight modification to the script provided by Adafruit to write the data to a log file (temp-hum.log) instead of google drive spreadsheet.

Actual work
Updated code on Github
To generate the log file that will be parsed by pygal on github
Adafruit’s code for the sensor forked on github

A short python script to generate the graphic using Pygal:

#!/usr/bin/env python

import pygal

temp = []
hum  = []

logdata = open('temp-hum.log','r')
for line in logdata.readlines():
  line = line.split()[1:]


line_chart = pygal.Line(width=1200)
line_chart.title = 'Temperature Humidity'
line_chart.add('Temperature *C', temp)
line_chart.add('Humidity %', hum) 
breadboard and flat cable
breadboard and flat cable
DHT22 and cables
DHT22 and cables
r-pi and all
r-pi and all
DHT22 sensor
DHT22 sensor
r-pi with sensor
r-pi with sensor

And the graphic looks like:

Sources: Adafruit DHT22 tutorial

installing inotool on the Raspberry Pi

For the basic install and configuration example, see my previous post inotool for busy people

When installing on a R-pi, few tools will not be installed by default on Raspbian, proceed to install all of them *before* attempting to clone the git repository.

apt-get install python-configobj python-setuptools git python-jinja2 python-serial


raspberry pi GPIO project

The idea is to plot temperature, light an humidity inside my house.

2013-02-24 00.51.50

source of inspiration

installing mp3_scanner on mac os

install python 2.7
python-2.7 32-bit
python-2.7 64bit

install mutagen

tar zxvf mutagen-1.20.tar.gz
cd mutagen-1.20
python build
sudo python install

get mp3_scanner