Tweet Tracker is a standalone application for streaming tweets containing a search term on Twitter in real time for a predefined duration or number of tweets. It is built using Scala 3.2, ZIO and sttp. It logs the tweets it's streaming as Json objects to standard output.
Application can be configured via application.conf. You can also override config values with following environment variables.
Variable Name | Data Type | Description | Required |
---|---|---|---|
TOKEN | String | Twitter API v2 access token | Yes, otherwise defaults to change-me which won't work |
SEARCH_TERM | String | The term to search in tweets | No, defaults to crypto |
FOR_SECONDS | Int | How long to stream tweets, in seconds | No, defaults to 30 |
UP_TO_TWEETS | Int | Maximum number of tweets to stream | No, defaults to 100 |
For log configuration, see logback.xml.
Application is built with SBT. So, standard SBT tasks like clean
, compile
and run
can be used. To run the application locally:
sbt run
Example to stream up to 50 tweets containing bitcoin
for 5 seconds:
TOKEN=your-own-token SEARCH_TERM=bitcoin FOR_SECONDS=5 UP_TO_TWEETS=50 sbt run
To run automated tests, you can use test
and testOnly
tasks of SBT. To run all tests:
sbt test
To run specific test(s):
sbt 'testOnly fullyQualifiedTestClassName1 fullyQualifiedTestClassName2 ...'
You may also run the application in a Docker container. Environment variables mentioned in Configuration are passed to the container while building image so you don't have to pass them with -e
while creating the container with docker run
.
To build the Docker image:
First build an image locally with
```bash
sbt 'Docker / publishLocal'
Then start a container from generated Docker image with
docker run --rm tweet-tracker
- The streaming only logs to standard out. They could be persisted for future use.
- There is no statistics across multiple runs of the application, app runs for a single time, every time.
All contributions are welcome. Please feel free to send a pull request. Thank you.
Tweet Tracker is licensed with MIT License.