Retrieving tweet by tweet-id - python

Is it possible to stream tweets for a list of tweet-ids using tweepy or twython?
I am trying to use to Twython using
tweets = t.lookup_status(id=Id)
'Id' looping over a list of tweet-ids
but there are rate limitations I guess and in case of tweepy, using StreamListener, I can only get tweets for some particular track. In my case, I have a list of tweet_ids for which I need the tweet-text, created_at, source, url etc ...
Or is there any other option for this task?
I am quite new to this. Please excuse if the question is naive!

I'm not quite clear what it is you're after, but you can find tweets that match a certain tweet id using the following snippet (provided you have a consumer_key, consumer_secret, access_token, and access_token_secret from the Twitter API):
import tweepy
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
public_tweets = api.home_timeline()
good_tweet_ids = [555175389383774208, 555174725136437248]
for tweet in public_tweets:
if tweet.id in good_tweet_ids:
print "".join(x for x in tweet.text if ord(x) < 128)

Related

how to display full text of a tweets in tweepy?

hey guys i am using tweepy api to collect data from search where the word is pandemi and Indonesia but it seems that some of the tweets that i collect trunance with "...." or it just collect half of the tweets like ("my nam") can anyone shed some light? to fix this? thank you very much
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
api = tweepy.API(auth)
tweets = [status._json for status in tweepy.Cursor(api.search, q="pandemi indonesia -filter:retweets", lang="id", tweet_mode="extended").items(20)]
for tweet in tweets:
d = tweet["full_text"].encode('ascii',errors='ignore')
print(d)

Get list of followers and following for group of users tweepy

I was just wondering if anyone knew how to list out the usernames that a twitter user is following, and their followers in two separate .csv cells.
This is what I have tried so far.
import tweepy
import csv
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
csvFile = open('ID.csv', 'w')
csvWriter = csv.writer(csvFile)
users = ['AindriasMoynih1', 'Fiona_Kildare', 'daracalleary', 'CowenBarry', 'BillyKelleherTD', 'BrendanSmithTD']
for user_name in users:
user = api.get_user(screen_name = user_name, count=200)
csvWriter.writerow([user.screen_name, user.id, user.followers_count, user.followers_id, user.friends_id user.description.encode('utf-8')])
print (user.id)
csvFile.close()
Tweepy is a wrapper around the Twitter API.
According to the Twitter API documentation, you'll need to call the GET friends/ids to get a list of their friends (people they follow), and GET followers/ids to get their followers.
Using the wrapper, you'll invoke those API calls indirectly by calling the corresponding method in Tweepy.
Since there will be a lot of results, you should use the Tweepy Cursor to handle scrolling through the pages of results for you.
Try the code below. I'll leave it to you to handle the CSV aspect, and to apply it to multiple users.
import tweepy
access_token = "1234"
access_token_secret = "1234"
consumer_key = "1234"
consumer_secret = "1234"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
for user in tweepy.Cursor(api.get_friends, screen_name="TechCrunch").items():
print('friend: ' + user.screen_name)
for user in tweepy.Cursor(api.get_followers, screen_name="TechCrunch").items():
print('follower: ' + user.screen_name)

How to get twitter users screen-name or UserId from a specific geolocations?

I want to get tweets from specific geo-location, so i used tweepy (api.search) method. I am successfully getting tweets from the specific geo location. but I am not getting screen name or userid. I am expecting that show_user when True will return me the screen name, who is posting that tweet. but i am not getting any screen name. so please tell me the solution how can i get the screen name who is posting that tweet by given geo location. Using tweepy.
public_tweets = tweepy.Cursor(api.search, rpp=100,
geocode="44.269493,63.341332,5km",since="2018-05-01",show_user =
"True",tweet_mode="extended").items()
rpp is deprecated, use "count" instead (see https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html).
This works with "100km" ("5km" returned no result).
consumer_key = '***'
consumer_secret = '***'
access_token = '***'
access_token_secret = '***'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
tweets = api.search(count=100,geocode="44.269493,63.341332,5km",since="2018-05-01")
for tweet in tweets:
print(tweet.user.id_str, tweet.user.screen_name, tweet.text)

With tweepy how can you get favorites and retweets on a tweet?

I have written this code that simply looks at the most 10 recent tweets about a certain query. I want to somehow get the number of favorites and retweets on it.
import tweepy
import time
import sys
consumer_key='…'
consumer_secret='…'
access_token='…'
access_token_secret='…'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
query="query"
non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd)
new_tweets = api.search(q=query,count=1)
for tweet in new_tweets:
# Get favorites and retweets here
WOM=new_tweets[0].created_at-new_tweets[len(new_tweets)-1].created_at
tweet.favorite_count and tweet.retweet_count is what you are looking for.

How to sort list of tweets from Tweepy by date

I am currently incorporating a sidebar into my website that will list tweets from various members of my team in order of most recent. I concatenated together the past 10 tweets from 2 random twitter users but can not figure out a good method to sort them. Any help would be appreciated. Here's the code I have thus far.
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, acess_token_secret)
api = tweepy.API(auth)
context = dict()
context['tweets'] = api.user_timeline(screen_name='tweetsauce', count=10, include_rts=False) + api.user_timeline(screen_name = 'neiltyson', count=10, include_rts=False)

Categories

Resources