This project provides a real-time Twitter stream listener using the tweepy
library and the Twitter API v2. It's designed to continuously monitor tweets from a specified user, printing new tweets to the console as they are posted.
Before you start, ensure you have the following:
- Python 3.6 or higher installed on your system.
- A Twitter Developer account and access to the Twitter API v2.
- A Bearer Token from your Twitter developer portal.
-
Clone the repository:
git clone https://github.com/BTI-US/twitter-stream-listener.git cd twitter-stream-listener
-
Install dependencies: Install the required Python libraries using the following command:
pip install tweepy python-dotenv
-
Setup environment variables: Create a
.env
file in the root directory of the project with the following content:BEARER_TOKEN=your_bearer_token_here
Replace
your_bearer_token_here
with your actual Bearer Token.
The script uses command-line arguments to specify the user ID of the Twitter account to monitor. Ensure you have the numeric user ID of the Twitter account.
To run the script, use the following command from the root directory of the project:
python stream_listener.py <user_id>
Replace <user_id>
with the numeric user ID of the Twitter account you want to monitor.
- Real-time Streaming: Monitors tweets in real-time from a specified Twitter user.
- Secure Authentication: Uses environment variables to securely manage the Bearer Token.
- Flexible: Easily change the Twitter user you are monitoring by passing a different user ID as a command-line argument.
Run the following command to use pytest to test the script:
py -m pytest py_test.py
Contributions are welcome! Please feel free to submit pull requests or create issues if you have suggestions or encounter bugs.
This project is licensed under the MIT License - see the LICENSE file for details.