Skip to content

Instantly share code, notes, and snippets.

@hugobowne
Last active August 6, 2026 06:03
Show Gist options
  • Select an option

  • Save hugobowne/18f1c0c0709ed1a52dc5bcd462ac69f4 to your computer and use it in GitHub Desktop.

Select an option

Save hugobowne/18f1c0c0709ed1a52dc5bcd462ac69f4 to your computer and use it in GitHub Desktop.
NOTE: this code is for a previous version of the Twitter API and I will not be updating in the near future. If someone else would like to, I'd welcome that! Feel free to ping me. END NOTE. Here I define a Tweet listener that creates a file called 'tweets.txt', collects streaming tweets as .jsons and writes them to the file 'tweets.txt'; once 100…
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)
@larryjune09

Copy link
Copy Markdown

Working with older Twitter API code like this is still useful for understanding how streaming data collection and listeners work, especially for learning or maintaining legacy projects. Writing tweets to a file in real time is a simple but effective approach for data logging and analysis.
Even in completely different industries, structured data and presentation matter a lot—similar to how GOSSiP Hong Kong focuses on delivering a well-organized and engaging user experience through its digital presence and brand identity.

@liammartian

Copy link
Copy Markdown

This is actually a useful example for anyone learning about Twitter/X API streaming and real-time data collection workflows. Even though the code is based on an older API version, the overall concept of listening to live events, storing JSON responses, and processing large streams of data is still very relevant today. Projects that depend on real-time analytics usually require efficient handling of incoming data, proper storage optimization, and reliable parsing logic to avoid performance issues over time.

I’ve worked with similar tracking and analytics concepts on platforms that process continuously updated datasets. For example, PERM Tracker organizes large amounts of PERM processing information, timeline estimations, and case analytics in a structured way so users can easily follow trends and understand current processing activity without manually analyzing raw data.

@jimmywilliams09

Copy link
Copy Markdown

فكرة جمع التغريدات المباشرة وتخزينها بصيغة JSON مفيدة جدًا لمشاريع تحليل البيانات والتعلم الآلي، خاصة عند التعامل مع تدفقات البيانات الحية من منصات التواصل الاجتماعي. صحيح أن تغييرات Twitter API قد تجعل بعض الأكواد القديمة غير متوافقة، لكن هذا النوع من المشاريع يظل مفيدًا لفهم كيفية التعامل مع الـ Streaming APIs وتنظيم البيانات بشكل عملي.

أنا مهتم دائمًا بمشاريع البرمجة وتحليل البيانات، ووجدت بعض المقالات والشروحات المفيدة على تحميلات التي تتحدث عن أدوات المطورين والتقنيات الحديثة بطريقة سهلة وواضحة.

@Olivia-Kerry

Copy link
Copy Markdown

This is a useful example for understanding how Twitter streaming data can be collected and saved for later analysis. Even though the code was written for an older API version, the overall approach remains valuable for developers learning about real-time data collection and processing. Similar concepts are often applied in educational platforms and tools such as an assignment submission portal, where data handling and storage play an important role. Thanks for sharing this helpful code snippet and explanation.

@liamcasper170-hub

Copy link
Copy Markdown

This resource provides useful technical information and demonstrates how sharing knowledge can help developers and technology enthusiasts learn from one another. Open collaboration and detailed examples make it easier for users to understand concepts, solve problems, and improve their skills. I appreciate content like this because it encourages learning, experimentation, and community-driven knowledge sharing. Whether someone is a beginner or an experienced developer, practical resources can be extremely valuable for expanding technical understanding. Thank you for sharing this information and contributing to a culture of learning and collaboration that benefits people interested in technology and software development.
Many mobile users search for information about the 0329 which network code to identify the carrier associated with this SIM prefix. Understanding network codes can help users verify network information and choose suitable packages. For detailed information about the 0329 network code. The website provides useful resources on SIM prefixes, network identification, and mobile carrier details.

@itsShauns

Copy link
Copy Markdown

I've dealt with similar integrations, and one thing that really helped was adding proper error handling for API failures and rate limits. Keeping detailed logs also made troubleshooting much easier. After making a few small optimizations on a website integration, the whole setup became far more reliable.

@leo-carter880

Copy link
Copy Markdown

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 موقع اختارلي الرسمي.

@itsShauns

Copy link
Copy Markdown

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.

@andrewsymond96-coder

Copy link
Copy Markdown

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.

@oscar25468127-art

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment