Monday 13 April 2015

Taking and tweeting a photo with raspberry pi


At first I was going to create a timelapse of my cherry tree while blooming, then I decided to make a tweet once a day with a image.

Timelapse

Based on older post on how to make a Timelapse with Rapberry Pi camera module, I made small change. Rather than do a loop of x images I choose to use cronjob to run the script every 15 minutes. The script is simple and short.
#!/bin/bash

DIR=/home/pi/cherrytree
/usr/bin/raspistill -w 1920 -h 1080 -rot 180 -n -t 1000 -o $DIR/$(date -u +"%Y%m%d-%H%M-%S").jpg

Next add to your cronjob your interval, I use every 15 min.
*/15 * * * * /bin/bash /home/pi/cherry.sh >/dev/null 2>&1

Twitter bot

There's more than one way to cook an egg... There are also many ways to make a twitter bot.
I installed Twitter CLI
sudo apt-get install ruby-dev
gem install t
You will also have to create or have access to an twitter app to authorize the CLI interface.


Here is a simple script I use to take picture and tweet it. Every time I run this script, I just overwrite the image, but you can collect them by naming the file like in the script above.
#!/bin/bash
DIR=/home/pi/autotwitter
DATE=$(date -u +"%A %d %B %Y")
/usr/bin/raspistill -w 800 -h 460 -rot 180 -n -t 1000 -o $DIR/twitter.jpg
/usr/local/bin/t update 'Image of the day, '"${DATE}"'. #CherryBlossoms #raspberrypi #cli ' --file=$DIR/twitter.jpg
Once a day this script runs by cronjob at 12:01
1 12 * * * /bin/bash /home/pi/twitter.sh >/dev/null 2>&1
In addition to that, you can auto follow your followers in the same script by adding following line to the twitter script.
/usr/local/bin/t groupies | xargs /usr/local/bin/t follow