├── LICENSE ├── README.md ├── config.py ├── reply_tweets_bot.py ├── update_status_bot.py └── user_details_bot.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Farhadur Raja Fahim 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Twitter Bot 2 | ___ 3 | Simple Twitter bot using Tweepy and Python. 4 | 5 | Tweepy is a Python library which provide access to Twitter API. 6 | ## Installation 7 | ``pip install tweepy`` 8 | ## Usage 9 | Before run any file please edit **[config.py](https://github.com/FarhadurFahim/twitter-bot/blob/master/config.py)** file according to your **[Keys and access token](https://dev.twitter.com/oauth/overview/application-owner-access-tokens)**. 10 | 11 | ``python3 update_status_bot.py`` 12 | 13 | Goto your Twitter account profile you can see result. 14 | 15 | ___ 16 | There is a blog, how to create bot. Details is [here] (https://medium.com/@frfahim/create-a-simple-twitter-bot-with-python-and-tweepy-60ff5d4d3ad9#.9n0xy5fjd "Medium blog") 17 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | consumer_key = "Your consumer key" 2 | consumer_secret = "Your consumer secret" 3 | 4 | access_token = "Your access token" 5 | access_token_secret = "Your access token secret" 6 | -------------------------------------------------------------------------------- /reply_tweets_bot.py: -------------------------------------------------------------------------------- 1 | import tweepy 2 | 3 | #import twitter apps configaration file from config.py file 4 | from config import * 5 | 6 | #Authentication using keys & accesstoken 7 | auth = tweepy.OAuthHandler(consumer_key, consumer_secret) 8 | auth.set_access_token(access_token, access_token_secret) 9 | api = tweepy.API(auth) 10 | 11 | twt = api.search(q="Hello World") 12 | 13 | #list of strings that we want to check from tweets 14 | txt = ['Hello world!', 15 | 'Hello World!', 16 | 'Hello World!!!', 17 | 'Hello world!!!', 18 | 'Hello, world!', 19 | 'Hello, World!'] 20 | 21 | #Its can take many time 22 | for st in twt: 23 | for s in txt: 24 | if s == st.text: 25 | usr = st.user.screen_name 26 | msg = ("@%s Hello!" %(usr)) 27 | st = api.update_status(msg, st.id) 28 | -------------------------------------------------------------------------------- /update_status_bot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import tweepy 3 | 4 | #import twitter apps configaration file from config.py file 5 | from config import * 6 | 7 | #Authentication using keys & accesstoken 8 | auth = tweepy.OAuthHandler(consumer_key, consumer_secret) 9 | auth.set_access_token(access_token, access_token_secret) 10 | api = tweepy.API(auth) 11 | 12 | api.update_status(status="This is a sample tweet using Tweepy with python") 13 | -------------------------------------------------------------------------------- /user_details_bot.py: -------------------------------------------------------------------------------- 1 | import tweepy 2 | 3 | #import twitter apps configaration file from config.py file 4 | from config import * 5 | 6 | #Authentication using keys & accesstoken 7 | auth = tweepy.OAuthHandler(consumer_key, consumer_secret) 8 | auth.set_access_token(access_token, access_token_secret) 9 | api = tweepy.API(auth) 10 | 11 | #Donal Trump Twitter account 12 | user = api.get_user('realDonaldTrump') 13 | 14 | print("Name:", user.name) 15 | print("User id: ", user.id_str) 16 | print("Description: ", user.description) 17 | print("Location:",user.location) 18 | print("Time zone: ", user.time_zone) 19 | print("Number of Following:",user.friends_count) 20 | print("Number of Followers:",user.followers_count) 21 | print("Number of tweets: ", str(user.statuses_count)) 22 | 23 | --------------------------------------------------------------------------------