Giter Club home page Giter Club logo

twitter-stream-bot-data-gatherer's Introduction

twitter-stream-bot-data-gatherer

An application to watch the Twitter stream and send accounts to the Botometer API for analysis. The results are stored in a SQLite database.

Prerequisites

Before using this application, credentials for the following are required:

Twitter API Credentials

The application connects to the Twitter stream API to query Twitter user's to Botometer for analysis.

To get access to the Twitter API, a developer account is needed. You can apply for one here and find more information about the application process here.

Once you have a developer account, go to the developer portal to create an application.

When creating the application, provide a unique name and follow the instructions. The application's API key and secret will be shown (aka. consumer_key and consumer_secret). Furthermore, you will need to generate an access token and access token secret to use the Twitter stream API. Go to your application, click Keys and tokens > Access Token and Secret > Generate. Store the credentials somewhere safe as they will be needed later.

Botometer API Credentials

The application uses the Botometer API to collect bot scores for Twitter users.

To get access to the Botometer API, a RapidAPI account is needed. You can create one here.

Once you have a RapidAPI account, go to the Botometer API pricing page and subscribe to the Basic or Pro plan.

Note

The Pro plan requires a credit or debit card to be added to the RapidAPI account.

Once you have chosen a plan, go to the RapidAPI developer dashboard. Then, go to security page for the default-application. The application key (API key) will be shown. Store it somewhere safe as it will be needed later.

Further details on accessing the Botometer API can be found here.

Dependencies

Install the application's dependencies using one of the options below:

# Poetry
poetry install --no-dev
# Pip
pip install -r requirements.txt
# Or use Docker!
# Please refer to the heading below

Usage

$ python twitter-stream-bot-data-gatherer/main.py -h

usage: main.py [-h] [-t TRACK] [-f DATABASE_NAME] [-d]
               rapidapi_key twitter_app_auth

An application to watch the Twitter stream and send accounts to the Botometer
API for analysis. The results are stored in a SQLite database.

positional arguments:
  rapidapi_key          Botometer Rapid API key.
  twitter_app_auth      Twitter application credentials.

optional arguments:
  -h, --help            show this help message and exit
  -t TRACK, --track TRACK
                        A hashtag to track. Can be specified more than once.
  -f DATABASE_NAME, --database_name DATABASE_NAME
                        Name of the database file. Defaults to: twitter-
                        stream-bot-data-gatherer.
  -d, --debug           Enable debug messages.

Tracking a Single Hashtag

python twitter-stream-bot-data-gatherer/main.py <rapidapi_key> \
  '{"consumer_key": "", "consumer_secret": "", "access_token": "", "access_token_secret": ""}' \
  --track '#StandWithUkriane'

Tracking Multiple Hashtags

python twitter-stream-bot-data-gatherer/main.py <rapidapi_key> \
  '{"consumer_key": "", "consumer_secret": "", "access_token": "", "access_token_secret": ""}' \
  -t '#StandWithUkriane' \
  -t '#RefugeesWelcome' \
  -t '#Ukrania'

Modifying the SQLite Database Name

python twitter-stream-bot-data-gatherer/main.py <rapidapi_key> \
  '{"consumer_key": "", "consumer_secret": "", "access_token": "", "access_token_secret": ""}' \
  -t '#StandWithUkriane' \
  # The database will be named 'twitter-db.db'
  -f 'twitter-db'

Docker ๐Ÿ‹

Build the container image:

docker build -t twitter-stream-bot-data-gatherer:v0.1.0 .

Run the application and persist the SQLite database:

docker run -it --name twitter-stream-bot-data-gatherer \
    -v absolute/path/to/store/db:/usr/src/app/db \
    twitter-stream-bot-data-gatherer:v0.1.0 <rapidapi_key> \
    '{"consumer_key": "", "consumer_secret": "", "access_token": "", "access_token_secret": ""}' \
    --track '#StandWithUkriane'

SQLite Database Structure

The SQLite database will contain one table called data. Within the table will be three columns:

  1. screen_name: The screen name of the Twitter account.

  2. status_json: The full JSON response of the Tweet Object (aka. Status) from the Twitter stream.

  3. botometer_json: The full JSON response from the Botometer API.

My Related Work

Acknowledgments

This application would not be possible without the work of the Observatory on Social Media at Indiana University who created Botometer. Please see the Botometer FAQ page for further information on Botometer.

Authors -- Contributors

License

This project is licensed under the MIT License - see the LICENSE for details.

twitter-stream-bot-data-gatherer's People

Contributors

dbrennand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.