-
Star
(255)
You must be signed in to star a gist -
Fork
(137)
You must be signed in to fork a gist
-
-
Save hugobowne/18f1c0c0709ed1a52dc5bcd462ac69f4 to your computer and use it in GitHub Desktop.
| class MyStreamListener(tweepy.StreamListener): | |
| def __init__(self, api=None): | |
| super(MyStreamListener, self).__init__() | |
| self.num_tweets = 0 | |
| self.file = open("tweets.txt", "w") | |
| def on_status(self, status): | |
| tweet = status._json | |
| self.file.write( json.dumps(tweet) + '\n' ) | |
| self.num_tweets += 1 | |
| if self.num_tweets < 100: | |
| return True | |
| else: | |
| return False | |
| self.file.close() | |
| def on_error(self, status): | |
| print(status) |
I've worked with similar integrations, and adding proper error handling for API failures and rate limits made a big difference. Keeping clear logs also helped a lot when tracking down issues. After a few small optimizations on the website integration, the setup became much more stable and reliable.
I've dealt with similar integrations, and adding better error handling for API failures and rate limits really improved the overall performance. Keeping detailed logs made it much easier to identify and fix problems. After making a few small changes to the site integration, the system became more stable and dependable.
Thanks for sharing this code and the discussion. It's helpful to see the improvements suggested for handling files and avoiding resource leaks. I also found useful programming resources on موقع تحميلات الرسمي that are worth exploring.
It looks like this example uses an older version of the Twitter API with Tweepy, but it's still helpful for understanding how tweet streaming and JSON data collection work. If you're building a similar project today, you'll likely need to update the code to match the latest API version and authentication methods. For more useful tech resources, tools, and guides, you can also explore موقع اختارلي الرسمي.