# Path: performanceplatform/collector/ga/lib/helper.py
# def create_client(credentials):
#     if "CLIENT_SECRETS" in credentials and "STORAGE_PATH" in credentials:
#         return from_secrets_file(
#             credentials['CLIENT_SECRETS'],
#             storage_path=credentials['STORAGE_PATH'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )
#     elif "ACCOUNT_NAME" in credentials:
#         return from_private_key(
#             credentials['ACCOUNT_NAME'],
#             private_key_path=credentials['PRIVATE_KEY'],
#             storage_path=credentials['STORAGE_PATH'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )
#     else:
#         return from_credentials_db(
#             credentials['CLIENT_SECRETS']['installed'],
#             credentials['OAUTH2_CREDENTIALS'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )


from datetime import datetime
from performanceplatform.collector.ga.lib.helper import create_client
from performanceplatform.client import DataSet
import pytz
import sys
        timestamp = _timestamp()
        return {
            "_timestamp": timestamp,
            "_id": timestamp,
            "unique_visitors": visitor_count,
            "for_url": for_url
        }


class Realtime(object):
    def __init__(self, credentials):
        self._client = create_client(credentials)

    def execute_ga_query(self, query):
        return self._client._service.data().realtime().get(
            **query
        ).execute()

    def query(self, query):
        response = self.execute_ga_query(query)

        if "rows" in response:
            visitor_count = int(response["rows"][0][0])
        else:
            visitor_count = 0

        return visitor_count


def _timestamp():

# Path: performanceplatform/collector/ga/lib/helper.py
# def create_client(credentials):
#     if "CLIENT_SECRETS" in credentials and "STORAGE_PATH" in credentials:
#         return from_secrets_file(
#             credentials['CLIENT_SECRETS'],
#             storage_path=credentials['STORAGE_PATH'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )
#     elif "ACCOUNT_NAME" in credentials:
#         return from_private_key(
#             credentials['ACCOUNT_NAME'],
#             private_key_path=credentials['PRIVATE_KEY'],
#             storage_path=credentials['STORAGE_PATH'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )
#     else:
#         return from_credentials_db(
#             credentials['CLIENT_SECRETS']['installed'],
#             credentials['OAUTH2_CREDENTIALS'],
#             http_client=HttpWithBackoff(),
#             ga_hook=track_ga_api_usage,
#         )


# Path: performanceplatform/collector/ga/realtime.py
from datetime import datetime
from performanceplatform.collector.ga.lib.helper import create_client
from performanceplatform.client import DataSet
import pytz
import sys

        timestamp = _timestamp()
        return {
            "_timestamp": timestamp,
            "_id": timestamp,
            "unique_visitors": visitor_count,
            "for_url": for_url
        }


class Realtime(object):
    def __init__(self, credentials):
        self._client = create_client(credentials)

    def execute_ga_query(self, query):
        return self._client._service.data().realtime().get(
            **query
        ).execute()

    def query(self, query):
        response = self.execute_ga_query(query)

        if "rows" in response:
            visitor_count = int(response["rows"][0][0])
        else:
            visitor_count = 0

        return visitor_count


def _timestamp():

    timezone = pytz.UTC