An open API service indexing awesome lists of open source software.

https://github.com/philippe2803/twitter-analytics-wrapper

A simple Python wrapper to download tweets data from the Twitter Analytics platform. Particularly interesting for the impressions metrics that are unavailable on current Twitter API. Also works for the videos data.
https://github.com/philippe2803/twitter-analytics-wrapper

analytics analytics-api data-analysis data-mining impression metrics python-library python2 python3 tweets twitter twitter-analytics-platform video-statistics

Last synced: 1 day ago
JSON representation

A simple Python wrapper to download tweets data from the Twitter Analytics platform. Particularly interesting for the impressions metrics that are unavailable on current Twitter API. Also works for the videos data.

Awesome Lists containing this project

README

          

Twitter analytics downloader
========

This script downloads the tweets report from the analytics section of a twitter account (including impressions).
You can specify dates for period longer than the last 28 days default period from the Twitter analytics interface.

The twitter analytics platform used to have a limit of 91 days. In the latest iteration Twitter allows for periods of a month worth of data to be doenloaded. For periods longer thatn 28-31 days the script splits the downloading of reports in multiple requests.

This was created so we can get impressions data for every tweets as there is no API endpoints specifically for those metrics (as of today).

Installation

Selenium uses a few binaries (Chromedriver, xvfb) that needs to be installed beforehand with the following command:

```commandline
$ sudo apt-get install chromium-chromedriver xvfb
```

Then you can install the library with pip

```commandline
$ pip install twitter-analytics

```

A simple download for the last 28 days (default period) is done as follow:

```python
from twitter_analytics import ReportDownloader

reports = ReportDownloader(
username='',
password='',
)

report_filepath = reports.run()
```

For specific date range and/or period over 90 days, you can launch the report download as follow:

```python
from twitter_analytics import ReportDownloader
import csv

reports = ReportDownloader(
username='',
password='',
from_date='03/28/2014', # must be in string format 'mm/dd/yyyy' and nothing before October 2013 (twitter restriction).
to_date='12/31/2016'
)

reports_filepath = reports.run() # list of filepaths of downloaded csv reports

# Then you can parse the csv simply as follow
tweets = list()
for report in reports_filepath:
with open(report, 'r') as csvfile:
r = csv.DictReader(csvfile)
rows = [row for row in r]
tweets += rows

```

If you encounter issues, submit it on this repo. I also accept pull requests.

## Mac OS install prerequisites

- xvfb: Install XQuartz. Download the installer from [here](https://www.xquartz.org).
- Chromedriver: The easiest way to obtain this is via [Homebrew](https://brew.sh):

```commandline
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

$ brew tap homebrew/cask
$ brew cask install chromedriver
```

Please note that `chromedriver` was migrated from `homebrew/core` to `homebrew/cask`.

# If you are installing from this repository:

1. Clone/Download (and unzip) this repo in a known location in your computer

2. Open a terminal and navigate to the location chosen for step 1

3. In the terminal type the following

```
python setup.py install --force
```