Skip to main content

twimer

Stream Tweets into Your Favorite Databases

Build Status

Analyzing tweets reveals very interesting insights about events in a specific time and location, people's opinions about the news, etc. twimer aims to make the data collection easier for you so you can focus on your data analysis only! This tool stores tweets with certain keywords and from specific geographic regions into JSON files or MongoDB databases.

Twitter API

To use twimer, you need to obtain CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET from Twitter Developer. You can either set these as environment variables or directly pass them to twimer.

Installation

Simply install this package by running the following command:

pip install twimer 

Usage

In the current version, you can stream the tweets using keywords and store them in files (JSON and JSON.tar.gz) and MongoDB databases.

  • To store tweets that contain keyword1 and keyword2 keywords as JSON (tar.gz) files into the my_path directory:
import twimer

stream_tweet = twimer.Twimer(CONSUMER_KEY, 
                             CONSUMER_SECRET, 
                             ACCESS_TOKEN, 
                             ACCESS_TOKEN_SECRET, 
                             storage_method='targz', 
                             file_path=my_path)
stream_tweet.start_streaming(filters=['keyword1', 'keyword2'])
  • To store the tweets in a MongoDB database using url mongo_url:
import twimer

stream_tweet = twimer.Twimer(CONSUMER_KEY, 
                             CONSUMER_SECRET, 
                             ACCESS_TOKEN, 
                             ACCESS_TOKEN_SECRET, 
                             storage_method='mongodb', 
                             mongo_url=mongo_url)
stream_tweet.start_streaming(filters=['keyword1', 'keyword2'])

The my_url is in mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]] format. If you set your Twitter credentials as environment variables, you do not need to pass them and can simply run the following code.

import twimer

stream_tweet = twimer.Twimer(storage_method='targz', 
                             file_path=my_path)
stream_tweet.start_streaming(filters=['keyword1', 'keyword2'])

Local MongoDB Database

To store tweets using MongoDB locally, you can use docker-compose by running docker-compose up. Note that you need to install docker on your system before running this command. To view the MongoDB Express dashboard, simply open http://localhost:8081 on your browser. The default username and password for MongoDB are set to root and example and you need to update them to prevent unauthorized access to your local database.

Contribution

You are very welcome to contribute to this project with your code (as pull-requests), mention the bugs, or ask for new features (as GitHub Issues), or just tell your friends about it!

You can also directly contact me by email.

Metadata

Release files for Twimer 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Twimer 0.0.5
File Size Uploaded
Twimer-0.0.5.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Twimer 0.0.5
File Interpreter ABI Platform
Twimer-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 11.2 kB

Release files / Twimer-0.0.5.tar.gz

Download URL Twimer-0.0.5.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
508ec07071af31c5d29d21c954cdf5a4d67a78d73427d9bf5253e8193e9d7188
BLAKE2b-256 checksum
How to use checksums
d96382591c1ca5efff3f4f0efa160f81a5d168d2d0f1546ca024b344adb8fea1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release files / Twimer-0.0.5-py3-none-any.whl

Download URL Twimer-0.0.5-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3bf140c9667a522c7d267a8307bbf1252a7a7c87027881959d47b0ba7990a3e6
BLAKE2b-256 checksum
How to use checksums
3c7fad72cbb9e058e694a51da6c4c7144094e60399e818c2dd8156b7fee8298f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page