Metadata-Version: 2.1
Name: bsi-sentiment
Version: 0.0.3
Summary: BSI Tool for Sentiment Analysis
Home-page: https://github.com/scortino/bsi-sentiment
Author: Stefano Cortinovis, Pietro Domietto, Elio Scarci, Kasra Zamanian
Author-email: scortino@pm.me
License: UNKNOWN
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Requires-Dist: nltk (>=3.4.5)
Requires-Dist: snscrape (>=0.3.4)
Requires-Dist: textblob (>=0.15.3)
Requires-Dist: tweepy (>=3.9.0)
Requires-Dist: GetOldTweets3 (>=0.0.11)

# BSI Sentiment Analysis Pipeline

![CI](https://github.com/fastai/fastai/workflows/CI/badge.svg) [![PyPI](https://img.shields.io/pypi/v/bsi-sentiment?color=blue&label=pypi%20version)](https://pypi.org/project/bsi-sentiment/#description) [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

BSI Sentiment is a Python library created at [BSI Bocconi](https://github.com/BSI-Bocconi) to download tweets and perform basic sentiment analysis on them.

## Installation 

BSI Sentiment can be installed using the `pip` package manager:

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

## CLI Usage

```console
foo@bar:~$ sentiment -h

usage: sentiment [-h] [-c CONFIG] [-a ANALYZER] [-q query] [-s SINCE] [-u UNTIL] [-n GEO] [-r RADIUS] [-l LANG] [--user username] [--result_type {recent,popular,mixed}]
                 [--max_tweets MAX_TWEETS] [--tweepy]
                 {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.
```

## Examples

### As a CLI Tool

```console
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

```python
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:
* [Stefano Cortinovis](https://github.com/scortino) (PL)
* [Pietro Dominietto](https://github.com/PietroDomi)
* [Elio Scarci](https://github.com/eliox98)
* [Kasra Zamanian](https://github.com/kasrazn97)

