Skip to main content

BSI Tool for Sentiment Analysis

Project description

BSI Sentiment Analysis Pipeline

CI PyPI License: GPL v3

BSI Sentiment is a Python library created at BSI Bocconi to download tweets and perform basic sentiment analysis on them.

Installation

BSI Sentiment can be installed using the pip package manager:

foo@bar:~$ pip install bsi-sentiment --upgrade

CLI Usage

foo@bar:~$ sentiment -h

usage: sentiment [-h] [-c CONFIG] [-a ANALYZER] [-q QUERY] [-s SINCE] [-u UNTIL] [-g GEO] [-r RADIUS] [-l LANG] [--user USERNAME] [--result_type {recent,popular,mixed}] [--max_tweets MAX_TWEETS] [--tweepy] [--credentials CREDENTIALS]
                 [--quiet]
                 {analyze,configure,download} [DEST]

BSI Tool for Sentiment Analysis. Tweets can be downloaded using either Snscrape (default) or Tweepy.

positional arguments:
  {analyze,configure,download}
                        Action to perform.
  DEST                  Output file location. Analysis/configuration/download output file is stored here. Default is current directory.

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
                        Config file location. If action is 'analyze' or 'download', configuration file is read from here.
  -a ANALYZER, --analyzer ANALYZER
                        Analyzer method for sentiment analysis. Available options are {'vader','textblob-pa','textblob-nb'}. Default is 'vader'.
  -q QUERY, --query QUERY
                        A query text to be matched
  -s SINCE, --since SINCE
                        A lower bound date (UTC) to restrict search. Default is 7 days before --until. Used only by Snscrape.
  -u UNTIL, --until UNTIL
                        An upper bound date (not included) to restrict search. Default is today. Tweepy has a 7 day hard limit, while Snscrape has no such limit.
  -g GEO, --geo GEO     Return only tweets by users from given geolocation. It must be a location name (e.g. 'Milan') if using Snscrape or a string of the form 'latitude,longitude' if using Tweepy.
  -r RADIUS, --radius RADIUS
                        Must be used together with --geo. Return only tweets by users within a given radius from the selected location. It must be either in 'mi' or 'km' (e.g. '15km')
  -l LANG, --lang LANG  Restrict language of the tweets retrieved. Must be an ISO 639-1 code (e.g. en, it, etc.). Default is no language restriction. Used only by Tweepy.
  --user USERNAME       Restrict search to tweets from specified username.
  --result_type {recent,popular,mixed}
                        Type of tweets to retrieve. Can be either 'recent', 'popular' or 'mixed'. Default is 'mixed'. Used only by Tweepy.
  --max_tweets MAX_TWEETS
                        The maximum number of tweets to be retrieved. Default is 10. In the case of Tweepy, if greater API rate limit is reached, the program waits for 15 minutes before trying again.
  --tweepy              Use Tweepy instead of the default Snscrape to download tweets.
  --credentials CREDENTIALS
                        Path to JSON file containing Tweepy credentials. See examples/credentials.json to see how the file should be formatted.
  --quiet               No stdout output when downloading or analyzing tweets. Default is verbose.

Examples

As a CLI Tool

foo@bar:~$ sentiment analyze ./results.csv --analyzer="vader" -q "us elections" --since="2020-08-01" --until="2020-11-30" --geo="New York" --radius="100km" -l "en" --max_tweets=100

As a Python Library

from bsi_sentiment.twitter import search_tweets_sn

tweets = search_tweets_sn(
  q="us elections",
  since="2020-08-01",
  until="2020-11-30",
  near="New York",
  radius="100km",
  lang="en",
  max_tweets=100
)

tweets.get_sentiment(method="vader")
tweets.to_csv("./results.csv")

Contributors

The BSI members that contributed to this project are:

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

bsi_sentiment-0.0.4-py3.10.egg (25.1 kB view details)

Uploaded Source

bsi_sentiment-0.0.4-py3.9.egg (26.1 kB view details)

Uploaded Source

bsi_sentiment-0.0.4-py3.8.egg (25.0 kB view details)

Uploaded Source

bsi_sentiment-0.0.4-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file bsi_sentiment-0.0.4-py3.10.egg.

File metadata

  • Download URL: bsi_sentiment-0.0.4-py3.10.egg
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for bsi_sentiment-0.0.4-py3.10.egg
Algorithm Hash digest
SHA256 71e6b20515937dc3e200294ae30416b5cfdd6a7b7d977dff90c4ae4b2538f7a5
MD5 2659a123b17ae14820c8b254522ec44c
BLAKE2b-256 81bd730d11a6c07a22d25fac16b2638c95daf58cbdb0abda6399dc54fbc69ac0

See more details on using hashes here.

File details

Details for the file bsi_sentiment-0.0.4-py3.9.egg.

File metadata

  • Download URL: bsi_sentiment-0.0.4-py3.9.egg
  • Upload date:
  • Size: 26.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for bsi_sentiment-0.0.4-py3.9.egg
Algorithm Hash digest
SHA256 34d5313987fc41465cd87c8f739aadaecea2aecb2840df078ebd07d31ea97981
MD5 4acb85061120537a61d402e3e56317db
BLAKE2b-256 bce91d5a8f5eef9cdbd0faa3c5472398885b04ebf3824c204478ab5ec0dc0977

See more details on using hashes here.

File details

Details for the file bsi_sentiment-0.0.4-py3.8.egg.

File metadata

  • Download URL: bsi_sentiment-0.0.4-py3.8.egg
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for bsi_sentiment-0.0.4-py3.8.egg
Algorithm Hash digest
SHA256 0a812d9179ce738a548cabed862238cc4c3bac3ef436e3304b371e86d6fe03b2
MD5 cbb93a5f3953aab267ace852a95326d5
BLAKE2b-256 9ea7d47a6678a3bd985ec3128eca16d694a0d67149f6c90ae2db002bf3a482bd

See more details on using hashes here.

File details

Details for the file bsi_sentiment-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: bsi_sentiment-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 25.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6

File hashes

Hashes for bsi_sentiment-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 da0443f60fa402be16f24f560fccefbdbcd8c684bf10e9c4f0effaaa745b4998
MD5 583b9416be43f068e534fb48f09e3fea
BLAKE2b-256 27529e2f1d3876088865aca4cae2e7204fa529dd1b17616881bdc55f7ee1d430

See more details on using hashes here.

Supported by

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