-
So, I've been trying to fix a little script that I have here. I am able to retweet the message that I want using Cursor Search, but I wanted to add a condition that the bot profile needs to be following the person before it retweets Let’s say person A is followed by the bot and posts something like: #RTMe I've been trying to do it with
and then checking a relation with But as I am getting the array for the user_ids I am not able to check one by one, If I am to make a for statement will probably consume too much memory, is there another way? |
Beta Was this translation helpful? Give feedback.
Replies: 13 comments
-
I'm not sure I understand what you're trying to do here. Also, if you just wanted the IDs of the users you're following, you can use In any case, to answer your question, you can use |
Beta Was this translation helpful? Give feedback.
-
It's says that 'API' object has no attribute 'lookup_friendship' |
Beta Was this translation helpful? Give feedback.
-
The method in question is |
Beta Was this translation helpful? Give feedback.
-
Oops, sorry. I will try that right now! |
Beta Was this translation helpful? Give feedback.
-
Am I doing something wrong? |
Beta Was this translation helpful? Give feedback.
-
Like I said, For code block usage, see https://docs.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks. |
Beta Was this translation helpful? Give feedback.
-
I want to check for multiple relationships, tho. |
Beta Was this translation helpful? Give feedback.
-
You can use |
Beta Was this translation helpful? Give feedback.
-
Oh, that makes sense. I was thinking about that. So I can just do like:
and then |
Beta Was this translation helpful? Give feedback.
-
Also note, |
Beta Was this translation helpful? Give feedback.
-
Yep, I was seeing that, I just created a new profile account not following anyone and tried it out. But for some reason its not working. I mean it is liking and retweeting the post. But its not checking properly if the person is being followed by me. I am trying to debug it, but not successfully so far. This is what I got for tweet in tweepy.Cursor(api.search, q=('#EuQueroMuitoTestarIsso')).items(numeroTweets):
try:
seguindo = api.friends_ids()
friendships = api.lookup_friendships(user_ids = seguindo)
for friendship in friendships:
print(friendship.is_following)
if(friendship.is_following):
tweet.favorite() |
Beta Was this translation helpful? Give feedback.
-
For each search result, this is looking up all the users you're following; looking up the relationships for those users; for each relationship, checking if you're following them in that relationship, which of course you are, since you looked up all the users you're following to begin with; and then favoriting the same Tweet for each user you're following. This is redundant in almost every way. Again, I'm not sure what you're trying to accomplish here. Like I said initially, if you want to check that the user who Tweeted is someone you're following, you can simply use |
Beta Was this translation helpful? Give feedback.
-
Okay, I am sorry. I was very sleepy, I took a better look at the documentation and I feel really dumb now, thanks for the patience, everything is working great! |
Beta Was this translation helpful? Give feedback.
I'm not sure I understand what you're trying to do here.
API.friends
already returns users you're following. Why pass it back toAPI.show_friendship
? If you already have the Tweet/Status
object, you can simply check if the ID of the user who Tweeted is in your list (using theuser
attribute of theStatus
object and the correspondingid
attribute of that User object, e.g.tweet.user.id
), or if you wanted to check it in realtime, useAPI.show_friendship
with that user ID.Also, if you just wanted the IDs of the users you're following, you can use
API.friends_ids
instead.In any case, to answer your question, you can use
API.lookup_friendships
to bulk lookup relationships to 100user_ids
at …