python - Tweepy 针对用户进行关注
问题描述
我发现自己需要一个机器人来关注 Twitter 上的用户。
当我说用户时,我指的不是追随者,而是我会用“光标”找到的随机用户。我正在尝试将我的 twitter 机器人修改为喜欢特定搜索的时间轴,使其成为跟随用户进行该搜索的机器人。我不知道如何实现的是如何将时间线中的用户准确定位到“create_friendship()”?我不是针对特定用户,所以我不想指定“Id”或“screen_name”等。
在 Tweepy 文档中我找不到解决方案,也许在我的眼皮底下,但我是新手,我可以使用一些帮助。
这是我用来点赞推文的 twitter 机器人的代码。
import tweepy
import time
auth = tweepy.OAuthHandler('','')
auth.set_access_token('','')
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
search = "The searc"
nrTweets = 100
for tweet in tweepy.Cursor(api.search, search).items(nrTweets):
try:
print('User succesfully followed')
tweet.favorite() #in here i should be able to create a friendship as i like
time.sleep(60)
except tweepy.TweepError as e:
print(e.reason)
except StopIteration:
break
我怎样才能把这个机器人变成一个以我喜欢推文的方式关注人们的机器人?(用于使用特定关键字的搜索)
解决方案
如果有人关心,我就是这样解决的。
# Write a function named collatz() that has one parameter named number. If
# number is even, then collatz() should print number // 2 and return this value.
# If number is odd, then collatz() should print and return 3 * number + 1
# Then write a program that lets the user type in an integer and that keeps
# calling collatz() on that number until the function returns the value 1.
# Add try and except statements to the previous project to detect whether the
# user types in a noninteger string. Normally, the int() function will raise a
# ValueError error if it is passed a noninteger string, as in int('puppy'). In the
# except clause, print a message to the user saying they must enter an integer.
try:
number = int(input(("Enter an integer number ")))
def collatz():
global number
if number % 2 == 0:
print(int(number/2))
number = (number/2)
elif number % 2 == 1:
print(int(3*number+1))
number = (3*number+1)
else:
return
while number != 1:
collatz()
except:
print("man, an integer number please! ")
推荐阅读
- c# - 构建表达式树以将元素动态添加到集合 c#
- javascript - 排序前如何装饰mongo文档?
- loops - 带有项目的ansible循环
- angular - 角材料步进生成
- razor - 我是否“正确”地构建了我的 Razor 应用程序?
- swift - 如何在导航栏内居中图像(SwiftUI)
- visual-studio-code - 如何在 VScode 中禁用对纯文本文档的建议?
- javascript - 如何动态生成包含一些动态内容的文本文件,然后将其附加到用户的默认邮件中?
- c++ - Petalinux Recipe-app 用于混合 C 和 C++ 应用程序
- python - 运行 Ansible 2.9.10 fortinet.fortios 剧本的问题