Git Product home page Git Product logo

nanigans-reporting-api's Introduction

NanStats

Welcome to NanStats; a Python adapter for the Nanigans Reporting API.

Getting Started

pip install nanstats

Basic Usage

Add Credentials:

You can use the nanigans.set_default_config in a live Python environment.

>>> import nanigans
>>> nanigans.auth.credentials == None
True
>>> nanigans.set_default_config('xxxxxxxx', 'xxxxxxxx', 123456)
>>> nanigans.auth.credentials
{'token': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'username': 'xxxxxxxx', 'password': 'xxxxxxxx', 'site': 123456}

OR

You can edit the config.py file to set default values.

  • Add username to config.py
  • Add password to config.py
  • Add site to config.py

Start making requests:

>>> import nanigans
>>> stats = nanigans.facebook.get_stats()
>>> stats.ok
True
>>> print(stats)
<Nanigans Response [OK]>
>>> stats.data
[{'date': '2016-05-09', 'impressions': '0', 'clicks':'0', 'fbSpend':'0.00', 'budgetPool': 'A'},...]

You can also switch sites by regenerating credentials:

>>> nanigans.auth.credentials
{'token': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'username': 'xxxxxxxx', 'password': 'xxxxxxxx', 'site': 123456}
>>> nanigans.change_site_id(987654)
{'token': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'username': 'xxxxxxxx', 'password': 'xxxxxxxx', 'site': 987654}

Access Facebook, Multichannel and Publisher Data

Facebook Native

>>> stats = nanigans.facebook.get_stats()
>>> stats.ok
True
>>> print(stats)
<Nanigans Response [OK]>
>>> stats.data
[{'date': '2016-05-09', 'impressions': '0', 'clicks':'0', 'fbSpend':'0.00', 'budgetPool': 'A'},...]

Multichannel (e.g. Twitter, Instagram, Facebook)

>>> stats = nanigans.multichannel.get_stats()
>>> stats.ok
True
>>> print(stats)
<Nanigans Response [OK]>
>>> stats.data
[{'date': '2016-05-09', 'impressions': '0', 'clicks':'0', 'fbSpend':'0.00', 'budgetPool': 'A'},...]

Publishers (e.g. MoPub)

>>> stats = nanigans.publisher.get_stats()
>>> stats.ok
True
>>> print(stats)
<Nanigans Response [OK]>
>>> stats.data
[{'date': '2016-05-09', 'impressions': '0', 'clicks':'0', 'fbSpend':'0.00', 'budgetPool': 'A'},...]

The Depth Parameter

A saved view in Nanigans can contain hierarchies of attributes. Depth allows you to drill down deeper into your aggregations.

When querying a saved view, depth=1 returns a top-level summary, depth=2 returns a drill down into the first listed attribute set, depth=3 returns a drill down into the second list attribute set etc.

In the example below I have 6 different attributes, see the difference from depth=1 to depth=6:

>>> import nanigans
>>> stats = nanigans.multichannel.get_stats('xxxxxxx', depth=1)
>>> stats.data[0]
{'actions_3': '639', 
'linkClickRaw28dClick': '28337', 
'fbSpend': '33150.39', 
'actions_1': '453', 
'actions_13': '28337', 
'impressions': '4383246', 
'actions_6': '10780', 
'actions_7': '968'}
>>> stats = nanigans.multichannel.get_stats('xxxxxxx', depth=6)
>>> stats.data[0]
{'context': 'FakeContext',
 'date': '2016-06-06',
 'audience': 'Github Users',
 'budgetPool': 'US',
 'fbSpend': '1235.34',
 'actions_1': '15',
 'actions_13': '451',
 'ad': 'FakeAd',
 'placementId': '123456789', 
 'actions_3': '8',
 'actions_7': '37',
 'strategyGroup': 'FakeStrategyGroup',
 'actions_6': '18',
 'structure2Objective': 'LINK_CLICKS',
 'impressions': '150875',
 'linkClickRaw28dClick': '451'}

Testing

To test, run one of the following:

python -m nanigans.api_tests
python -m nanigans.models_tests
python -m nanigans.structures_tests
python -m nanigans.utils_tests

Acknowledgements

This library is an adapted version of other request-response based interfaces (e.g. TwitterAds, Requests).

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.