tweepy

How to restart tweepy script in case of error?

心不动则不痛 提交于 2019-11-28 19:57:06
I have a python script that continuously stores tweets related to tracked keywords to a file. However, the script tends to crash repeatedly due to an error appended below. How do I edit the script so that it automatically restarts? I've seen numerous solutions including this ( Restarting a program after exception ) but I'm not sure how to implement it in my script. import sys import tweepy import json import os consumer_key="" consumer_secret="" access_key = "" access_secret = "" auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_key, access_secret) api =

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

こ雲淡風輕ζ 提交于 2019-11-28 15:51:48
问题 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

Tweepy won't install on python 3.7; shows “syntax error”

有些话、适合烂在心里 提交于 2019-11-28 14:16:48
Before I begin, I'd like to preface that I'm relatively new to python, and haven't had to use it much before this little project of mine. I'm trying to make a twitter bot as part of an art project, and I can't seem to get tweepy to import. I'm using macOS High Sierra and Python 3.7. I first installed tweepy by using pip3 install tweepy and this appeared to work, as I'm able to find the tweepy files in finder. However, when I simply input import tweepy into the IDLE, I get this error: Traceback (most recent call last): File "/Users/jacobhill/Documents/CicadaCacophony.py", line 1, in <module>

ImportError: No module named tweepy

拈花ヽ惹草 提交于 2019-11-28 13:57:55
I installed pip in a virtual environment. It installed without errors. Here's what I get when I run sudo pip install tweepy after activating the venv: Requirement already satisfied (use --upgrade to upgrade): tweepy in /usr/local/lib/python2.7/dist-packages/tweepy-3.1.0-py2.7.egg Requirement already satisfied (use --upgrade to upgrade): requests==2.4.3 in /usr/local/lib/python2.7/dist-packages/requests-2.4.3-py2.7.egg (from tweepy) Requirement already satisfied (use --upgrade to upgrade): requests-oauthlib==0.4.1 in /usr/local/lib/python2.7/dist-packages/requests_oauthlib-0.4.1-py2.7.egg (from

tweepy Streaming API : full text

元气小坏坏 提交于 2019-11-28 13:53:42
I am using tweepy streaming API to get the tweets containing a particular hashtag . The problem that I am facing is that I am unable to extract full text of the tweet from the Streaming API . Only 140 characters are available and after that it gets truncated. Here is the code: auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) api = tweepy.API(auth) def analyze_status(text): if 'RT' in text[0:3]: return True else: return False class MyStreamListener(tweepy.StreamListener): def on_status(self, status): if not analyze_status(status

Get data from Twitter using Tweepy and store in csv file

血红的双手。 提交于 2019-11-28 07:06:01
I'm new to Python, Twitter, and Tweepy. I managed to pull data from Twitter, but I now want to store it into a CSV file. My code is: #!/usr/bin/python import tweepy auth = tweepy.auth.OAuthHandler('XXXXXX', 'XXXXXXX' auth.set_access_token('XXX-XXX', 'XXX' api = tweepy.API(auth) for tweet in tweepy.Cursor(api.search, q="google", since="2014-02-14", until="2014-02-15", lang="en").items(): print tweet.created_at, tweet.text This prints data out on CLI, but I want it to output to a CSV file. I tried a few different options, but it only outputted the first tweet and not all tweets. Royendgel

No module named pip.req

淺唱寂寞╮ 提交于 2019-11-28 04:38:10
I am installing tweepy, but I am running into an error about pip.req. I have pip installed, but for some reason pip.req still can't be found. I did a bunch of research online and the most I could find was some issue about incompatibilities between zapo (?) and python 2.7 causing the same error for some other user. The discussion was unclear about how to solve the problem, though. Thanks! $ python2 setup.py install Traceback (most recent call last): File "setup.py", line 5, in <module> from pip.req import parse_requirements ImportError: No module named pip.req It looks like it would work if you

Py2exe, Runtimeerror with tweepy

谁说胖子不能爱 提交于 2019-11-28 01:37:20
I wanted to use the python plugin for twitter called tweepy. in my main.py file I just imported tweepy import tweepy My setup-file looks like this: from distutils.core import setup import py2exe setup( windows=[{ "script": 'main.py', }], options={ "py2exe": { "includes": ["sip", "tweepy"] } } ) When i execute python setupy.py py2exe via command line I get this repeating codeblock until I get an RuntimeError: maximum recursion depth exceeded in comparison. File "C:\Python34\lib\site-packages\py2exe\hooks.py", line 291, in __getattr__ self.__finder.safe_import_hook(renamed, caller=self) File "C:

Getting full tweet text from “user_timeline” with tweepy

余生颓废 提交于 2019-11-27 23:14:00
问题 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

urllib.request in Python 2.7

妖精的绣舞 提交于 2019-11-27 19:48:06
I can use urllib.request module with Python 3.1. But when I execute the same program using Python 2.7, an error comes along the lines of; AttributeError: 'module' object has no attribute 'request'. I believe this error is because theres no request module in urllib for Python 2.7. Because I need to use tweepy i'll have to stick with Python 2.7 since tweepy does not support Python 3. So how I can use urllib.request module in Python 2.7? use urllib2.urlopen It is also possible to use six module to make code for both python2 & python3: from six.moves import urllib # ... result = urllib.request