how to display full text of a tweets in tweepy? - python

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)

Related

Tweepy Geolocation Search Not Returning Results

I've pulled this code together from a few other posts on here focusing on the topic of searching for Tweets in a certain geographical area. Unfortunately, all I receive from this code is a blank spreadsheet. I have tried a few different iterations with additional parameters added to no avail. Is there something I am missing here?
import tweepy
import csv
consumer_key = 'XXXXX'
consumer_secret = 'XXXXX'
access_token = 'XXXXX'
access_token_secret = 'XXXXX'
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)
search_area = tweepy.Cursor(api.search, count=100, geocode="37.5407,77.4360,5km").items()
output = [[tweet.id_str, tweet.created_at, tweet.text.encode("utf-8"), tweet.favorite_count, tweet.retweet_count,
tweet.entities.get('hashtags'), tweet.entities.get('user_mentions'), tweet.entities.get('media'),
tweet.entities.get('urls')] for tweet in search_area]
with open('city_tweets.csv', 'w') as f:
writer = csv.writer(f)
writer.writerow(["id", "created_at", "text", "likes", "retweets", "hashtags",
"user mentions", "media", "links"])
writer.writerows(output)
37.5407, 77.4360 is 37°32'26.5"N 77°26'09.6"E, which is in a relatively unpopulated area in Western China, where Twitter is blocked, so it makes sense for there to be no Tweets from there in the past week.
Did you mean 37.5407, -77.4360?, which is pretty much the center of Richmond, Virginia.

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)

Retrieving tweet by tweet-id

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)

Categories

Resources