Skip to content

Scrape tweets related to keywords and run sentiment analysis on them

Notifications You must be signed in to change notification settings

bmistry12/twitter-scraper

Repository files navigation

Twitter Scraper

DeepSource

Setup

Apply for a Twitter development account here. Naturally you'll also need a twitter account.

Setting Up Credentials - Hashicorp Vault 🔒

Install Hashicorp Vault (if not already done so)
Various Download Links:

https://learn.hashicorp.com/vault/getting-started/install
https://www.vaultproject.io/downloads.html
https://chocolatey.org/packages/vault

Start up Vault Server

vault server -dev

Copy

Unseal Key: xxx
Root Token: xxx

Open new terminal

export VAULT_ADDR='http://127.0.0.1:8200'
export VAULT_DEV_ROOT_TOKEN_ID='xxx'

Check vault can be connected to & is running correctly

vault status

Put Secrets Into Vault

vault kv put secret/twitter consumer_key=<xxx> consumer_secret=<xxx> access_token=<xxx> access_token_secret=<xxx>

Get Secrets From Vault (sanity check)

vault kv get secret/twitter
vault kv get -field=consumer_key secret/twitter

Being Uncool and Not Using Vault

This of course still runs without Vault.
Comment out any references to credentials.py (e.g. in run.sh and as import credentials), and set the variables in historic_twitter_data.__main__ manually.

Run 🏃

./run.sh "<keywords>" <number_of_tweets_to_fetch> <output_json_filename> <output_csv_for_data>

The only required argument is keywords, which can be a string of different words seperated by commas.

Or, if for some reason you don't like the existence of shell scripts:

pip install -r requirements.txt
py credentials.py
py historic_twitter.py <keywords> <output json file name>
py json_analysis.py <output json file name> <output csv for data>
py mapper.py <output csv name>

This Code Sucks 🤢

See any issues or terrible code? Feel free to create an issue or PR to fix them.

To keep code consistent Flake8 should be used for linting checks. flake8 --max-line-length 100

About

Scrape tweets related to keywords and run sentiment analysis on them

Topics

Resources

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •