Skip to main content

Stream Tweets into Your Favorite Databases

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Twimer-0.0.5.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Twimer-0.0.5-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file Twimer-0.0.5.tar.gz.

File metadata

  • Download URL: Twimer-0.0.5.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for Twimer-0.0.5.tar.gz
Algorithm Hash digest
SHA256 508ec07071af31c5d29d21c954cdf5a4d67a78d73427d9bf5253e8193e9d7188
MD5 4d0a14318cc6e2b32a0a627bfbc262e7
BLAKE2b-256 d96382591c1ca5efff3f4f0efa160f81a5d168d2d0f1546ca024b344adb8fea1

See more details on using hashes here.

File details

Details for the file Twimer-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: Twimer-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for Twimer-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3bf140c9667a522c7d267a8307bbf1252a7a7c87027881959d47b0ba7990a3e6
MD5 ed7ddedbfbae5f1ca07a919075544951
BLAKE2b-256 3c7fad72cbb9e058e694a51da6c4c7144094e60399e818c2dd8156b7fee8298f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page