Skip to content

Instantly share code, notes, and snippets.

View ivanvenosdel's full-sized avatar

Ivan VenOsdel ivanvenosdel

View GitHub Profile
@ivanvenosdel
ivanvenosdel / pelican_build.py
Last active June 15, 2017 20:49
An example of a pelican project's Fabric-based fabfile.py converted to a pynt-based build.py, including in-project virtualenv support
import os
import shutil
from pynt import task
from pyntcontrib import safe_cd, execute
MODULE_PATH = os.path.abspath(__file__)
PROJECT_ROOT = os.path.dirname(MODULE_PATH)
REQUIREMENTS_PATH = os.path.join(PROJECT_ROOT, 'requirements.txt')
VENV_PATH = os.path.join(PROJECT_ROOT, 'venv')
@ivanvenosdel
ivanvenosdel / ga_realtime_reporting_service.py
Last active January 20, 2021 04:01
Python "requests", Google Analytics Realtime Reporting API (for oauth2 service accounts)
"""
Using "requests" to access Google Analytics Realtime Reporting API from python service
NOTE on google docs: The realtime reporting docs have samples for google-api-python-client.
**They do not work** at the time of this writing. The GA docs sample seems to refer to features that don't actually exist.
In any case, the new RR API is restfull and requests is a pleasent library so here is how to use it instead.
pip requirements: oauth2client, requests
"""
AssertionError: '{"body": {"city": "Someplace", "progress_patient_id": "someid", "name": "Pharmacy", "max_record_count": 1, "functions": [], "specialties": [], "ncpdpid": "?", "state_code": "SD", "zip_code": "43333"}, "site_user_id": "somegal", "originated_timestamp": "2013-1-1T00:00:00+05:00", "message_type": "pharmacysearch", "site_id": "SD001", "message_id": "totally_unique_d00d"}' != '{"body": {"city": "Someplace", "functions": [], "specialties": [], "name": "Pharmacy", "progress_patient_id": "someid", "max_record_count": 1, "state_code": "SD", "zip_code": "43333", "ncpdpid": "?"}, "site_user_id": "somegal", "originated_timestamp": "2013-1-1T00:00:00+05:00", "message_type": "pharmacysearch", "site_id": "SD001", "message_id": "totally_unique_d00d"}'