All Projects → opencredo → tornado-analytics

opencredo / tornado-analytics

Licence: MIT license
opencredo.com/blogs/building-a-google-analytics-dashboard-with-python3-tornado/

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects
Less
1899 projects
python
139335 projects - #7 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to tornado-analytics

Rust Learning
A bunch of links to blog posts, articles, videos, etc for learning Rust
Stars: ✭ 7,431 (+39010.53%)
Mutual labels:  blog-article
ReactCalculator
A React Native tutorial where you'll write a calculator app for Android and iOS.
Stars: ✭ 75 (+294.74%)
Mutual labels:  blog-article
blog
个人博客
Stars: ✭ 20 (+5.26%)
Mutual labels:  blog-article
blueshoes-kotlin-android
Projeto Kotlin Android - construção de um mobile-commerce chamado BlueShoes.
Stars: ✭ 46 (+142.11%)
Mutual labels:  blog-article
akka-java8-examples
Simple examples of using Akka Java 8 interface
Stars: ✭ 17 (-10.53%)
Mutual labels:  blog-article
guozeyu.com
我的网站文章的原始数据与历史
Stars: ✭ 17 (-10.53%)
Mutual labels:  blog-article
CQRSAndMediator-Microservice
A microservice architecture template which implements the CQRS and Mediator patterns
Stars: ✭ 86 (+352.63%)
Mutual labels:  blog-article
mesos framework demo
A sample Mesos framework
Stars: ✭ 19 (+0%)
Mutual labels:  blog-article

Tornado G Analytics

This is a tornado application that queries Google analytics v3 API

Installation

Check out the sources and install the requirements:

python setup.py install

Install Redis for caching or add another caching class in utilities/cache.py and inherit it in base handler (handlers/base.py).

Configuration

Configure additional requests/second for your project in google developer console: https://developers.google.com/analytics/devguides/reporting/mcf/v3/limits-quotas

Set Per-user limit to more than 1.

Rename app_conf.yaml.example to app_conf.yaml

Then, use this file for configuration:

  • applicationSettings - these options are used for callbacks as well as server startup. For local development leave them as is.
  • googleAnalyticsApi - in your google developer console go to APIs & auth > credentials and create new service account. Your profileId is your google analytics profile ID.
  • Download client_secrets '.p12' file and add it to "utilities" or specify path to this file in config: keyFileLocation: '/Users/your_username/Projects/keys/client_secrets_real.p12'
  • googleOAuth - key value should contain key with your Client ID (Client ID for native application) and secret - Client secret
  • allowedDomain value should contain whitelisted domain, leave it blank ('') to allow all domains.

Start the server

python run.py

Deploying on OpenShift

  • Create new Python 3.3 application specifying this repo.
  • WHen creating native client application through google developer console - specify web application and input your full application name (with your domain, i.e. http://analytics-rusenask.rhcloud.com/login )
  • Checkout your newly created OpenShift repo and modify app_config.yaml, you can skip host, port settings since they will be overwritten by OpenShift environment variables anyway. Download your serivce account's p12 key, add it to utilities folder, commit it and push it to that OpenShift repo as well.
  • Add redis to your application: rhc add-cartridge http://cartreflect-claytondev.rhcloud.com/reflect?github=smarterclayton/openshift-redis-cart
  • Restart your application: rhc app-restart __your_app_name__

Troubleshooting OpenShift app

  • SSH into your application: rhc ssh __your_app_name__
  • Check logs in app-root/logs/python.log
  • you can modify code, add additional debugging information in /app-root/repo/

Adding new tables

  • Define your new query in utilities/gaclient.py Use https://developers.google.com/apis-explorer/#p/ to test your queries You can inherit or just edit GAcess class with your additional function, it should return raw response from google API.

  • Define a tornado handler in handlers/web_handlers.py. Use @unblock decorator to make calls asynchronous since google API is a blocking operation (at the time of writing this application there were no non-blocking clients or libraries available). This handler should return "render_to_string" since @unblock decorator writes whole response and returns it to client: return self.render_string('webhandler/data_table.html',

    data=data, table_title=table_title, headers=headers)

    here: data - is what populates rows

    table_title - surprisingly it names the table headers - populates table headers

  • Define your handler in urls.py

  • Add your table div in templates/index.html, then, in js section add loading div function all: loaddiv('#__your_created_div', '/your-new-url-to-data-table');

Style

For style this application uses https://almsaeedstudio.com/AdminLTE template, feel free to change base template and static css files to improve it or ruin it.

TODO

  • logging
  • testing
  • custom views
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].