{"id":16119395,"url":"https://github.com/codingchili/unicorn-analytics","last_synced_at":"2025-10-15T00:02:41.633Z","repository":{"id":87434609,"uuid":"157217591","full_name":"codingchili/unicorn-analytics","owner":"codingchili","description":"retrieve analytics from google APIs and visualize on a unicorn hat  - asyncio/aiohttp","archived":false,"fork":false,"pushed_at":"2022-03-30T14:42:49.000Z","size":52,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-12T15:51:41.231Z","etag":null,"topics":["aiohttp","asyncio","google-analytics","raspberry","raspberry-pi","unicornhat","youtube-api"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codingchili.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-12T13:26:39.000Z","updated_at":"2022-03-29T15:49:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"1483564f-25ac-48c3-9f0d-1892646f4874","html_url":"https://github.com/codingchili/unicorn-analytics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingchili%2Funicorn-analytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingchili%2Funicorn-analytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingchili%2Funicorn-analytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingchili%2Funicorn-analytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codingchili","download_url":"https://codeload.github.com/codingchili/unicorn-analytics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247464370,"owners_count":20942999,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aiohttp","asyncio","google-analytics","raspberry","raspberry-pi","unicornhat","youtube-api"],"created_at":"2024-10-09T20:54:02.502Z","updated_at":"2025-10-15T00:02:41.625Z","avatar_url":"https://github.com/codingchili.png","language":"Python","readme":"# unicorn-analytics\nUnicorn analytics retrieves analytics data from the **YouTube Analytics API** and **Google Analytics API**.\nThe unicorn in the story is the [unicorn hat HD](https://shop.pimoroni.com/products/unicorn-hat-hd). Page hits\nand video views are visualized as a snake crawling over the unicorn display. One snake equals one page load or view.\n\nIf you don't have that many views you can set a scaling factor - for example we can retrieve the statistics\nover the last week; and display them over 5 minutes - then refresh the statistics and play them again for 5 minutes.\n\nUnicorn analytics also supports operating in API mode, with a REST/WS API to control visualizations. This can be paired with the \neve.json events shipper to visualize network events.\n\n![sample image from internet](https://thumbs.gfycat.com/ConventionalFrightenedBorzoi-size_restricted.gif)\n\nGIF of me running the unicorn-analytics on a Raspberry PI 3, replaying page loads and youtube views for the last week over 5 minutes. I used the configuration that is checked in here: [unicorn-analytics/config](https://github.com/codingchili/unicorn-analytics/tree/master/config)\n\nRelated project: [pi-zero-ethermeter](https://github.com/codingchili/pi-zero-ethermeter)\n\n# Requirements\n\nYou need at least one raspberry pi with a unicorn HAT.\nThe raspberry pi needs python 3.5+ to support await/async.\n\nModules that **needs** to be installed,\n\n```console\npip install -r requirements.txt\n```\n\n# Setup for api mode\n\nFirst run the unicorn in api mode, this starts the ws and http api's.\n```\npython -m unicorn.run --server --port 9990\n```\n\nThen optionally run the eve.json shipper for the api mode, supports ws:// and http://.\n```\npython -m shipper.eve --file ./eve.json --server ws://localhost:9990 --token \u003ctoken\u003e\n```\n\nCheck the logs for more information and to ensure the application is operational. \n\n### Configuration\nFor security a token is required to communicate with the API endpoints. The token is\ngenerated on startup in api mode and logged, alternatively configured in `config/server.json`.\n\n# Setup for analytics/youtube\n\nThe following modules are used for authentication.\n\n- oauth2client: used to retrieve oauth2 tokens from google.\n- httplib2: to update the oauth token when expired.\n\nNote: the oauth token is for google communications. The token configured in `config/server.json` is just\nused for the server api, when running in api mode.\n\nNow is a good time to **configure your google APIs**, see the section on **Configuration**.\n\nTo start it all up run,\n```console\npython -m unicorn.run --analytics --youtube\n```\n\nMake sure you have configured everything first :smirk:\n\nThe first time it is launched it will ask you to open your browser and allow third party access.\nIf you don't have a browser available on your PI, please run as follows:\n```\npython -m unicorn.run (...) --noauth_local_webserver\n```\n\nAnd open your browser on another machine.\n\n### Configuration\nPerform the following and update `config/analytics.json` and `config/youtube.json`\n\n- create a new Google Analytics project, grab the view ID.\n- make sure there is a YouTube channel registered on your Google account.\n\nCreate a new API project on the google developers console\n- [developers console](https://console.developers.google.com/)\n- enable \"YouTube Analytics API\"\n- enable \"Analytics API\"\n\nCreate an OAUTH2 client secret by following these instructions;\n- https://developers.google.com/identity/protocols/OAuth2\n\nDownload it as json and place under `api_keys/analytics_secret.json` and `api_keys/youtube_secret.json`.\n\n# Additional notes\n\nFor the youtube analytics API we may **only** authenticate using a OAUTH2 token. Most of the examples in the docs assume \nthat we are a web application. Some hours later I actually found out that there IS a flow that can be used from the \ncommandline! Scroll to the bottom of the following page:\n\nhttps://developers.google.com/api-client-library/python/guide/aaa_oauth#the-oauth2client-library\n\nWith this we can actually generate oauth2 tokens without requiring a browser to be opened on the PI. If you \ndon't have a browser available in your environment please pass the commandline parameter\n\n```console\n--noauth_local_webserver\n```\n\n# Contributing\nAll contributions welcome. :fish: :sweat_drops:\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodingchili%2Funicorn-analytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodingchili%2Funicorn-analytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodingchili%2Funicorn-analytics/lists"}