The

goal of this tutorial is to get you write your own Twitter bot using Python and tweepy. We will get tweets based on Hashtag and Geo Graphical Area. First of all, We need to wrapper for python script to access Twitter account.

Read : How To Create Twitter App In 4 Easy Steps

Note Keys and Tokens we will use it in script. Next, we need to install tweepy. Tweepy is Python library for accessing the Twitter API. Tweepy will be used to access the twitter API with Python.




Install Tweepy From Command Line

Now, Its time to write python script. Create a new file with .py extension. Eg. twitterApp.py

Import tweepy and sleep library

Import tweepy to access twitter api and sleep to put time delay in script.


Define Consumer key, Secret and Tokens


Initialise Tweepy

Create object auth from tweepy library and set access token. method set_access_token() will be used to set access token.


Getting Tweets

Listing out tweets between 20th November 2016 to 03rd December, tweeted from silicon velly, having hashtag #php.

geocode='37.3875,122.0575,5000km' : Returns tweets based on latitude and longitude nearby 5000 kilo meters.
q='#php' : Hashtag whose tweets we want to use.
tweet.user.screen_name : Returns User Name of owner
tweet.favorite() : This function used to retweet the tweet
tweet.favorite() : Used to favorite the tweet
tweet.user.follow() : To follow the user
lang='en' : Returns tweets having language English only
items(10000) : Returns 10000 maximum tweets

Full Source Code

Script is now ready. Now, Run script using following command to set it loose in the world.



  1. This idea is mind blowing. I think everyone should know such information like you have described on this post. Thank you for sharing this explanation.Your final conclusion was good. We are sowing seeds and need to be patiently wait till it blossoms.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">