Change Bot From Hashtag To URL Tweepy

Viewed 30

Afternoon all

Currently i have a twitter bot that retweets, Likes & follows the user but the only problem i have is that it will only do that with a hashtag. its running off tweepy. is there anyway i can change the hashtag to a url instead. so i replace the hashtag with url to the tweet and it will still follow, like and retweet?

Heres my code

from time import sleep
from anettecurtain import *
from config import QUERY, FOLLOW, LIKE, SLEEP_TIME

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

print("Twitter bot which retweets,like tweets and follow users")
print("Bot Settings")
print("Like Tweets :", LIKE)
print("Follow users :", FOLLOW)

for tweet in tweepy.Cursor(api.search, q=QUERY).items():
    try:
        print('\nTweet by: @' + tweet.user.screen_name)

        tweet.retweet()
        print('Retweeted the tweet')

        # Favorite the tweet
        if LIKE:
            tweet.favorite()
            print('Favorited the tweet')

        # Follow the user who tweeted
        #check that bot is not already following the user
        if FOLLOW:
            if not tweet.user.following:
                tweet.user.follow()
                print('Followed the user')

        sleep(SLEEP_TIME)

    except tweepy.TweepError as e:
        print(e.reason)

    except StopIteration:
        break```

***AND MY CONFIG FILE ***

```# Edit this config file as you like

QUERY = '#hashtag'

LIKE = True 

FOLLOW = True

SLEEP_TIME = 1```

1 Answers

You can change the query string you pass to Tweepy api.search

QUERY = 'url:"https://github.com"'

According to Twitter documentation you can search by URL using the format above (url:<your url>)

Related