Skip to content

Commit 7644d07

Browse files
Create Tweepy.py
Closes
1 parent 53773bd commit 7644d07

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Twitter bot/Tweepy.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import tweepy
2+
3+
# Twitter API credentials
4+
consumer_key = 'your_consumer_key'
5+
consumer_secret = 'your_consumer_secret'
6+
access_token = 'your_access_token'
7+
access_token_secret = 'your_access_token_secret'
8+
9+
# Authenticate with Twitter
10+
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
11+
auth.set_access_token(access_token, access_token_secret)
12+
api = tweepy.API(auth)
13+
14+
# Mention timeline tweets
15+
def mention_timeline_tweets(username, count):
16+
try:
17+
# Get user timeline tweets
18+
tweets = api.user_timeline(screen_name=username, count=count)
19+
for tweet in tweets:
20+
# Mention the tweet author in a new tweet
21+
mention = f'@{tweet.user.screen_name} Hello! Just mentioning you.'
22+
api.update_status(mention, in_reply_to_status_id=tweet.id)
23+
print(f'Mentioned @{tweet.user.screen_name} in response to tweet: {tweet.text}')
24+
except tweepy.TweepError as e:
25+
print('Error:', str(e))
26+
27+
# Example usage
28+
mention_timeline_tweets('openai', 5)

0 commit comments

Comments
 (0)