You have an application using a database and would like to send messages to Twitter with information from this database but your app does not manage this use case.
db2twitter connects to your database, extract the data, format the result and send it to Twitter. db2twitter runs with every kind of databases supported by the SQLAlchemy Python library.
Tweet when you have a new comment in WordPress
Here is a simple example. You can not install any plugin for your WordPress and wish to send tweets as soon as a new comment is identified. Here is the full example you need to start your discovery of db2twitter !
Lets start by creating our needed configuration:
[twitter] consumer_key=bLoLNAWil4Whq18FDvinjJZALw consumer_secret=Pw54EJH5c4ICBGIuiWuJHlLTyJQDJVnfsosisKALWMhJW4szLKA access_token=9814918709-sLAHGLmG3iXkzq2Xgl1GQD1EbXUYnlo7hS1e5ya access_token_secret=J5eVuiAZygtyKAJTbZrjuf1MW0X54sSCt3q7icDCskRoiuy tweet={} just posted a comment on my blog. Thanks! [database] dbconnector=mysql+mysqlconnector dbhost=localhost database=wordpress dbuser=wordpress dbpass=V3rYS3cr3t dbtables=wp_comments, wp_comments_rows=comment_author [sqlite]sqlitepath=/var/lib/db2twitter/db2twitter.db
Now let’s install db2twitter with the Pip command:
# pip3 install db2twitter
We create a dedicated user for db2twitter to safely manipulate your data:
# adduser --home /var/lib/db2twitter --gecos "" db2twitter
Now create a /etc/db2twitter directory to store your db2twitter configuration. Next configure the good permissions of the directory and file:
# mkdir -p /etc/db2twitter # vim /etc/db2twitter/db2twitter.ini # chown db2twitter:root /etc/db2twitter/db2twitter.ini # chmod 640 /etc/db2twitter/db2twitter.ini
Now let’s add a line in your /etc/crontab in order to execute db2twitter on a regular basis:
*/10 * * * * db2twitter db2twitter /etc/db2twitter/db2twitter.ini
We’re all set! Now db2twitter will automatically retrieve your data from your wordpress database and tweet any new comment directly to your Twitter account!
More information about db2twitter
- db2twitter on Github (star it on Github if you like it )
- Official documentation of db2twitter on Readthedocs.io
- Another great example of db2twitter use by the job board LinuxJobs.fr
…and finally
You can help the Retweet Bot by donating anything through Liberaypay (also possible with cryptocurrencies) Even cents. That’s a big factor motivation 😉