This is a Twitter bot which looks for metions - once someone tweets a mention, it will record a video (or take a picture), upload to Twitter and tweet it back to them as a reply.
Built for a project at work, where people can stand in front of the iconic Brighton graffiti and get a picture or video of them.
It uses the Twitter streaming API to get the tweets in real time.
This runs on a Raspberry Pi with a standard Camera Module. As it only uses Python to run, it could be run on any compatible platform. The camera code is obviously for the Raspberry Pi, so would need to be tweaked for your needs.
If you run into any problems (or suggestions) then please add a Github Issue
The installation of this is a bit patchy as it's done from memory. However, it should be (fairly) self explanitory.
Download the code and put it in somewhere like /home/pi/tweetcam
Copy _config.cfg.skel, rename to _config.cfg and update the values.
setupdebug_mode- This stops the script from actually tweeting but output on the command linetwitter_username- The username of your twitter bot (without the @)
optionstweet_difference_limit- Time (in minutes) for the cutoff for replying to tweets (e.g. if it is over this it won't reply)
twitter_api- Your keys for the API apptweet_text- a list of dictionaries containing phrases that your bot can reply, if make sure they contain[[user]]to include the usernamephoto- for when the bot takes a picturevideo- for status with videopreperation- the tweet which is sent before recording startslate- for when the tweet is more than tweet difference limit
Run the bot.py script manually to make sure everything is OK.
python bot.py
This should loop through any mentions and, if less than your previously defined tweet_difference_limit, will reply with a video. Otherwise, it will reply with an apology.
Modify line 14 of StreamingDaemon to the correct path of your script. Copy it to /etc/init.d with a slightly more sensible name.
sudo cp tweets /etc/init.d/tweets
Ensure the script is executable
sudo chmod +x /etc/init.d/tweets
And initalise it as a service
sudo insserv /etc/init.d/tweets
Now you can run
sudo service tweets start
You can set up a cron job to run every 15 minutes or so to check the service is running. If it is, do nothing. If it's stopped for whateve reason, start it again.
Edit the crontab
sudo crontab -e
And add this to the bottom
*/15 * * * * sudo sudo /bin/sh /home/pi/tweet/servicecheck.sh
This will run the service check script every 15 minutes - restarting the process if it's not running