tweepy

How do I save streaming tweets in json via tweepy?

女生的网名这么多〃 提交于 2019-11-30 00:58:34
I've been learning Python for a couple of months through online courses and would like to further my learning through a real world mini project. For this project, I would like to collect tweets from the twitter streaming API and store them in json format (though you can choose to just save the key information like status.text, status.id, I've been advised that the best way to do this is to save all the data and do the processing after). However, with the addition of the on_data() the code ceases to work. Would someone be able to to assist please? I'm also open to suggestions on the best way to

How can I consume tweets from Twitter's streaming api and store them in mongodb

情到浓时终转凉″ 提交于 2019-11-29 20:00:05
I need to develop an app that lets me track tweets and save them in a mongodb for a research project (as you might gather, I am a noob, so please bear with me). I have found this piece of code that sends tweets streaming through my terminal window: import sys import tweepy consumer_key="" consumer_secret="" access_key = "" access_secret = "" auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_key, access_secret) api = tweepy.API(auth) class CustomStreamListener(tweepy.StreamListener): def on_status(self, status): print status.text def on_error(self, status

The best way to get a list of followers in Python with Tweepy

回眸只為那壹抹淺笑 提交于 2019-11-29 17:46:54
问题 Is there a better way to get a list of followers screen names with Tweepy than this: for follower in api.followers_ids('twitter'): print api.get_user(follower).screen_name 回答1: I think this is more efficient: for user in tweepy.Cursor(api.followers, screen_name="twitter").items(): print user.screen_name FYI, it uses followers/list twitter API call. 来源: https://stackoverflow.com/questions/17455107/the-best-way-to-get-a-list-of-followers-in-python-with-tweepy

Exclude retweets from twitter streaming api using tweepy

瘦欲@ 提交于 2019-11-29 15:55:45
问题 When using the python tweepy library to pull tweets from twitter's streaming API is it possible to exclude retweets? For instance, if I want only the tweets posted by a particular user ex: twitterStream.filter(follow = ["20264932"]) but this returns retweets and I would like to exclude them. How can I do this? Thank you in advance. 回答1: Just checking a tweet's text to see if it starts with 'RT' is not really a robust solution. You need to make a decision about what you will consider a retweet

Tweepy twitter oauth authentication not returning oauth_verifier

倾然丶 夕夏残阳落幕 提交于 2019-11-29 15:44:56
I am using a python library called "tweepy" for twitter. When I try to authorize the user, twitter is supposed to redirect to a callback url with auth_token and oauth_verifier. I am getting only auth_token in the url. Anyone else had the same problem? Twitter only uses oauth_verifier (PINs) for desktop applications. For web applications, Twitter bypasses this and does not use it. You can re-check your application settings at http://dev.twitter.com/apps 来源: https://stackoverflow.com/questions/4033789/tweepy-twitter-oauth-authentication-not-returning-oauth-verifier

How to save a tweepy Twitter stream to a file?

别来无恙 提交于 2019-11-29 14:54:51
问题 I have a working script that successfully gathers tweets that mention "stackoverflow". However, I want to run the script in iPython (rather than executive a separate .py file). Ideally, I just want to open it ipyb file, select run all, and let it run for a week or so (not closing my laptop of course) and in result I have a .json file with a week's worth of tweets. Here is what I have so far: from tweepy import Stream from tweepy import OAuthHandler from tweepy.streaming import StreamListener

Tweepy (Twitter API) Not Returning all Search Results

浪子不回头ぞ 提交于 2019-11-29 09:35:25
问题 I'm using the search feature with Tweepy for Twitter and for some reason the search results are limited to 15. Here is my code results=api.search(q="Football",rpp=1000) for result in results: print "%s" %(clNormalizeString(result.text)) print len(results) and only 15 results are returned. Does it have something to do with different pages of results or something? 回答1: The question is more about Twitter API instead of tweepy itself. According to the documentation, count parameter defines: The

Getting full tweet text from “user_timeline” with tweepy

隐身守侯 提交于 2019-11-29 05:42:37
I am using tweepy to fetch tweets from a user's timeline using the script included here . However, the tweets are coming in truncated: auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_key, access_secret) api = tweepy.API(auth) new_tweets = api.user_timeline(screen_name = screen_name,count=200, full_text=True) Returns: Status(contributors=None, truncated=True, text=u"#Hungary's new bill allows the detention of asylum seekers & push backs to #Serbia. We've seen push backs before so\u2026 https:// t.co/iDswEs3qYR", is_quote_status=False, ... That is, for some

Tweepy Streaming - Stop collecting tweets at x amount

允我心安 提交于 2019-11-29 02:34:01
I'm looking to have the Tweepy Streaming API stop pulling in tweets after I have stored x # of tweets in MongoDB. I have tried IF and WHILE statements inside the class, defintion with counters, but cannot get it to stop at a certain X amount. This is a real head-banger for me. I found this link here: https://groups.google.com/forum/#!topic/tweepy/5IGlu2Qiug4 but my efforts to replicate this have failed. It always tells me that init needs an additional argument. I believe we have our Tweepy auth set different, so it is not apples to apples. Any thoughts? from tweepy.streaming import

Getting tweet replies to a particular tweet from a particular user

做~自己de王妃 提交于 2019-11-28 23:50:45
I am trying to go through tweets of a particular user and get all replies on that tweet. I found that the APIv1.1 of twitter does not directly support it. Is there a hack or a workaround on getting the replies for a particular tweet. I am using python Streaming API. There is a workaround using the REST API. You will need the id_str and @username of the author of the original tweet you want to find replies to. You should use the Search API for the "@username" of the author. Go through the results looking for the 'in_reply_to_status_id' field to compare to the id_str of the specific tweet you