Bot para twitter

Estas son las notas rápidas sobre la instalación y configuración de un bot para enviar trinos, la primera parte estaba originalmente en la página de HackBo sin embargo por los cambios en la plataforma, la información que estaba ahí, no está disponible por el momento. Teniendo en cuenta que este bot es útil para algunas tareas de “activismo digital” he decidido replicar esa información en esta entrada de mi blog y extender la entrada original con las anotaciones del script y de los archivos necesarios para la configuración del bot.
Mis agradecimientos a @kmilo y @gpmeneses que en su momento me ayudaron con la primera configuración que hice de este bot.
Installation
apt-get install bti
Configuration

Now you have the command bti available on your shell and you have to complete the OAuth authorization process to be able to post on your twitter account.

First create your configuration file as:

# comments are allowed in the bti config file
# rename this to ~/.bti so that you do not need
# to constantly enter your account name and/or
# password on the command line every time you send
# a message.
account="your account"
password="your password"
host=twitter
# Example of a custom laconica installation
#host=http://army.twit.tv/api/statuses
logfile=.bti.log
action=update
#user="your proxy user"
#proxy="http://your proxy address:port"
#shrink-urls=yes

and put it in ~/.bti.
Consumer key and secret
You should register a new application to have access at your twitter following this link: https://twitter.com/apps/new.

  •  Application name: choose a different name from bti because that is already choosen.
  • Website: http://gregkh.github.com/bti/
  • client without callback
  • Application type: Read and Write

Twitter will give you the two keys you need and You will put these at the and of your .bti config file as:

consumer_key=ambarabaciccicocco
consumer_secret=trecivettesulcomò

Then try your first run:

$ bti

You will be prompted to browse a specific link and past back the pin you see. Then you will be asked to add other two rows in your configuration file and  when you have done it, well all the process is completed! with the command:

$ echo "tweet what you want" | bti --debug

You will be able to tweet all you want from the shell!

Script

Create your Script file as:

#!/bin/bash 

echo start: $(date) >> /var/log/bti.log 
echo >> /var/log/bti.log 

pausa=300 
for line in $(seq $(wc -l tweets.txt | awk '{print $1}')); do 
    tail -n +$line tweets.txt | head -n 1 | bti --debug >> /var/log/bti.log 
    sleep $pausa 
    bti --action user --user $(tail -n +$line retweets.txt | head -n 1) | head -n 1 | sed 's/\[\(.*\)\]/RT @\1/' | bti --debug >> /var/log/bti.log 
    sleep $pausa 
done

and put it in ~/tweets.sh

Create your tweets file as:

This is my first tweet using bti
This is my second tweet
Now a third one

and put it in ~/tweets.txt

Create your retweets file as:

myfavorytwitteraccount
anothergreattweeteraccount

and put it in ~/retweets.txt

Execute the script using ./tweets.sh
Anuncios