Adding Twitter Bot program

This commit is contained in:
Mysterious-Owl 2022-10-05 18:49:28 +05:30
parent 618f2fd966
commit ff6a82c8dc
4 changed files with 51 additions and 0 deletions

View File

@ -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.
<br>
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<br>

View File

@ -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)

View File

@ -0,0 +1,5 @@
[keys]
api_key=
api_secret_key=
access_token=
access_secret_token=

View File

@ -0,0 +1,2 @@
configparser
twython