Friday, 18 January 2013

Crontab : Automating our bot

After reading the first post you might be thinking that the Bot we just made is not at all automated it is just an application to post tweets.
Don't be disappointed after reading this post you definitely will be able to automate your application.
If you are a unix/linux programmer you might very well about unix cron jobs that allows you to automate any command line program chronologically and thats the sole magic we are looking forward to right know.
First of edit your file as follows:

import twitter
import random as rm
a=['python with php ver1','python with php ver2','python with php ver3','python with php ver4','python with php ver5','python with php ver6','python with php ver7','python with php ver8','python with php ver9','python with php ver10']
api = twitter.Api(consumer_key='your_key',consumer_secret='your_key',access_token_key='your_key',access_token_secret='your_key')
print status.text

Here as you can see what we did is that we created a list of post as twitter doesn't allow to post same tweet twice.
Now we will automate this chronologically to post tweets in a timely manner.
Now start your unix system and goto terminal and do the following things:

1.) Type the following command:

crontab -e.

What this command does is it opens the editor for creating a cron job file in your /var/tmp folder.

2.) The basic format of your cron job has following syntax:

       minute hour day month day-of-week command-line-to-execute

This defines the timely format for running your script
You find the reference here and here too

3.) Now I wanted to post a tweet each and every minute of everyday of every month and so on...So I edited my cron file as follows

       */2 * * * * /usr/bin/python /home/maitray/htdocs/

Now enter the new line at the end of the file and close it.It will be auto
Here the last parameter shows the location of your file.

4.) Alls well that ends well just check your twitter account for bots tweets
You can see my twitter page That has all the tweets posted by the bot.

And that concludes the complete tutorial for twitter bots using python.Thanks
And feel free to contact me for any related queries and feedback

Ads : Auctions ,Electronics, Cars, Fashion, Collectibles, Coupons and Much More Online Shopping from eBay is a wonderful site that allows you to have a unique shopping experience
check out the auctions here


  1. At you can try out all the combinations of the timing values and see when the job will run over the next few runs.

  2. The interactive cron simulator is now at

  3. at, you can set a long time-out cron-job each minute, with SMS and email alerts..