微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将机器人从 Hashtag 更改为 URL Tweepy

如何解决将机器人从 Hashtag 更改为 URL Tweepy

下午所有

目前我有一个推特机器人,可以转发、喜欢和关注用户,但我唯一的问题是它只能使用主题标签来做到这一点。它跑掉了tweepy。无论如何我可以将主题标签更改为网址。所以我用 url 替换了推文的主题标签,它仍然会关注、喜欢和转发?

这是我的代码

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```

解决方法

您可以更改传递给 Tweepy api.search 的查询字符串

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

根据Twitter documentation,您可以使用上述格式 (url:<your url>) 的 URL 进行搜索

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。