Receive rss by sms using python-rsstail and gammu
- Debian/Ubuntu/...
- A cellphone who works with gammu. See list here of supported phones here.
- gammu : Who will provide the ability to control your phone from a computer. Install it with
sudo apt-get install gammu
- rsstail : the python version not the original. This tools will output to the terminal the rss. You can install it with pip :
pip install rsstail
To install pip check this post on StackOverFlow.
- First connect your phone with usb cable or bluetooth to your computer. Thanks to Mathieu Lallemand who did a great post for the Sony K750i.
- Configure the phone using
gammu-config
in your terminal and set parameters who can be found on the gammu phone database. - To test your phone simply do an
echo "My first message" | /usb/bin/gammu --send SMS TEXT +*yournumber*
You can get all the available command of gammu here. - Grab your rss feeds. Like in my example the football results of the french Ligue 1 (I did this bot for a friend who loves football). My rss in the example looks like this : http://www.matchendirect.fr/rss/foot-ligue-1-c10.xml.
- Put it in rsstail like :
rsstail http://www.matchendirect.fr/rss/foot-ligue-1-c10.xml
I have to force encoding because of the type of my rss feed who have some problems (W3C say Your feed appears to be encoded as "UTF-8", but your server is reporting "US-ASCII"). So for me the command isPYTHONIOENCODING=utf8 rsstail --nofail http://www.matchendirect.fr/rss/foot-ligue-1-c10.xml
with--nofail
to don't exit if I have errors, andPYTHONIOENCODING
to force utf8 encoding. - We had the option to sort only the last line with
-n 1
and format it a little bit--format 'Football News: {title} the {updated}'
After we had :
Title: Ligue 1 : Rennes - PSG (score final : 1-3) Title: Ligue 1 : Rennes - PSG en direct Title: Ligue 1 : Montpellier - Saint-Etienne (score final : 0-1) Title: Ligue 1 : Montpellier - Saint-Etienne en direct
Now we have :
Football News: Ligue 1 : PSG - Lille (score final : 2-2) the 2014/01/19 21:45:00
- But we have a problem. We want only feed with "score" mentioned. For that we use
grep
with the option--line-buffered
otherwise it will doesn't work. We will have :
PYTHONIOENCODING=utf8 rsstail --nofail -n 1 --format 'Football News: {title} the {updated}' http://www.matchendirect.fr/rss/foot-ligue-1-c10.xml | grep --line-buffered "score"
- We will now pipe it using a
while ... read
loop to run command on every new line.
while read line
do
command
done
- We will modify a little bit the
gammu
command adding-text
to specify the text submitted. The loop will look like :
while read line; do /usr/bin/gammu --sendsms TEXT +*yournumber* -text "$line"; done
- With everything together we will have this :
user@host:~# PYTHONIOENCODING=utf8 rsstail --nofail --format 'Football News: {title} the {updated}' http://www.matchendirect.fr/rss/foot-ligue-1-c10.xml | grep --line-buffered "score" | while read line; do /usr/bin/gammu --sendsms TEXT +*yournumber* -text "$line"; done
I've finaly creat a script to be able to run with multiple phone numbers. Check gammu_rsstail.sh file.
#! /bin/bash
#Below put cellphone number like tel="068888888 068898989"
tel=""
#See this link to help you to format the rssfeed : http://python-rsstail.readthedocs.org/en/latest/
rsstail --nofail -n 2 --format 'Football News: {title} le {updated}' http://www.matchendirect.fr/rss/foot-ligue-1-c10.xml | grep --line-buffered "score" | while read line
do for t in $tel
do echo -e $t
done
echo $line
done
Enjoy !
Thanks to help of RssTail team and also Roux.