diff --git a/scripts/twitter_streamer_bot/README.md b/scripts/twitter_streamer_bot/README.md new file mode 100644 index 0000000..8e76233 --- /dev/null +++ b/scripts/twitter_streamer_bot/README.md @@ -0,0 +1,15 @@ +# TWITTER BOT + +This is a Twitter bot, it will like and retweet your tweet, containing some keyword and will print the url of tweet. +
+Here I used the twython library to use Twitter API, this library can be used to all the things mentioned in Twitter API document. + +## Prerequisites + +Check [requirements.txt](requirements.txt), for twython check [here](https://twython.readthedocs.io/en/latest/usage/install.html) +Generate your unique Twitter keys and token from [here](https://developer.twitter.com/en) by creating a [new app](https://developer.twitter.com/en/apps). + +## How to run the script +Update the keys and tokens in code. +Run the python file and enter the keyword you want to track, now any new tweet will automatically liked and retweeted. +It will print the link of tweet
diff --git a/scripts/twitter_streamer_bot/code.py b/scripts/twitter_streamer_bot/code.py new file mode 100644 index 0000000..a8029dd --- /dev/null +++ b/scripts/twitter_streamer_bot/code.py @@ -0,0 +1,29 @@ +from twython import Twython +from twython import TwythonStreamer +import configparser + + +class MyStreamer(TwythonStreamer): + # Overwriting function + def on_success(self, data): + if 'text' in data: + username = data['user']['screen_name'] + tweet_id = data['id'] + # Liking the tweet found + st.create_favorite(id=tweet_id) + # Retweeting the tweet with msg + st.update_status(status=f'Nice Tweet @{username}', in_reply_to_status_id=tweet_id) + print(f"https://twitter.com/{username}/status/{str(tweet_id)}") + + +config = configparser.ConfigParser() +config.read('config.ini') +api_key = config['keys']['api_key'] +api_secret_key = config['keys']['api_secret_key'] +access_token = config['keys']['access_token'] +access_secret_token = config['keys']['access_secret_token'] + +api = MyStreamer(api_key, api_secret_key, access_token, access_secret_token) +st = Twython(api_key, api_secret_key, access_token, access_secret_token) +keyword = input("Enter keyword to track: ") +api.statuses.filter(track=keyword) diff --git a/scripts/twitter_streamer_bot/config.ini b/scripts/twitter_streamer_bot/config.ini new file mode 100644 index 0000000..911597a --- /dev/null +++ b/scripts/twitter_streamer_bot/config.ini @@ -0,0 +1,5 @@ +[keys] +api_key= +api_secret_key= +access_token= +access_secret_token= \ No newline at end of file diff --git a/scripts/twitter_streamer_bot/requirements.txt b/scripts/twitter_streamer_bot/requirements.txt new file mode 100644 index 0000000..30a6b4a --- /dev/null +++ b/scripts/twitter_streamer_bot/requirements.txt @@ -0,0 +1,2 @@ +configparser +twython \ No newline at end of file