How to make a twitter bot using python

First go to apps.twitter.com and create a new application. Go to Permissions tab and make you that you have read and write access for your application. Then request the access tokens in the Key and Access Tokens tab.

See my previous post about the basic setup.

  • To make a new tweet:
mypost = 'This is my new tweet'
api.update_status(status=mypost)
  • To follow back every follower:
for follower in tweepy.Cursor(api.followers).items():
    follower.follow()
  • Add a cron task every 3 hours o'clock:
    • Edit your cron
crontab -e

Check cron help at arch linux.

0 */3 * * * /usr/bin/python /path/to/mybot.py

Latest posts