Exemplo n.º 1
0
def track_event(category=None, action=None, label=None):
    if not settings.analytics.getboolean('enabled'):
        return

    anonymousConfig = Config()
    anonymousConfig.anonimize_ip_address = True

    tracker = Tracker('UA-138214134-3', 'none', conf=anonymousConfig)

    try:
        visitor = pickle.loads(base64.b64decode(settings.analytics.visitor))
    except:
        visitor = Visitor()
        unique_id = long(random.getrandbits(32))
        visitor.unique_id = unique_id

    session = Session()
    event = Event(category=category, action=action, label=label, value=1)
    path = u"/" + u"/".join([category, action, label])
    page = Page(path.lower())

    tracker.add_custom_variable(CustomVariable(index=1, name='BazarrVersion', value=os.environ["BAZARR_VERSION"], scope=1))
    tracker.add_custom_variable(CustomVariable(index=2, name='PythonVersion', value=platform.python_version(), scope=1))
    if settings.general.getboolean('use_sonarr'):
        tracker.add_custom_variable(CustomVariable(index=3, name='SonarrVersion', value=sonarr_version, scope=1))
    if settings.general.getboolean('use_radarr'):
        tracker.add_custom_variable(CustomVariable(index=4, name='RadarrVersion', value=radarr_version, scope=1))
    tracker.add_custom_variable(CustomVariable(index=5, name='OSVersion', value=platform.platform(), scope=1))

    try:
        tracker.track_event(event, session, visitor)
        tracker.track_pageview(page, session, visitor)
    except:
        pass
    else:
        settings.analytics.visitor = base64.b64encode(pickle.dumps(visitor))
        with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
            settings.write(handle)
Exemplo n.º 2
0
def track_event(category=None, action=None, label=None):
    if not settings.analytics.getboolean('enabled'):
        return

    anonymousConfig = Config()
    anonymousConfig.anonimize_ip_address = True

    tracker = Tracker('UA-138214134-3', 'none', conf=anonymousConfig)

    try:
        if os.path.isfile(os.path.normpath(os.path.join(args.config_dir, 'config', 'analytics.dat'))):
            with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'analytics.dat')), 'r') as handle:
                visitor_text = handle.read()
            visitor = pickle.loads(codecs.decode(visitor_text.encode(), "base64"))
            if visitor.user_agent is None:
                visitor.user_agent = os.environ.get("SZ_USER_AGENT")
            if visitor.unique_id > int(0x7fffffff):
                visitor.unique_id = random.randint(0, 0x7fffffff)
        else:
            visitor = Visitor()
            visitor.unique_id = random.randint(0, 0x7fffffff)
    except:
        visitor = Visitor()
        visitor.unique_id = random.randint(0, 0x7fffffff)

    session = Session()
    event = Event(category=category, action=action, label=label, value=1)

    tracker.add_custom_variable(CustomVariable(index=1, name='BazarrVersion',
                                               value=os.environ["BAZARR_VERSION"].lstrip('v'), scope=1))
    tracker.add_custom_variable(CustomVariable(index=2, name='PythonVersion', value=platform.python_version(), scope=1))
    if settings.general.getboolean('use_sonarr'):
        tracker.add_custom_variable(CustomVariable(index=3, name='SonarrVersion', value=sonarr_version, scope=1))
    else:
        tracker.add_custom_variable(CustomVariable(index=3, name='SonarrVersion', value='unused', scope=1))
    if settings.general.getboolean('use_radarr'):
        tracker.add_custom_variable(CustomVariable(index=4, name='RadarrVersion', value=radarr_version, scope=1))
    else:
        tracker.add_custom_variable(CustomVariable(index=4, name='RadarrVersion', value='unused', scope=1))
    tracker.add_custom_variable(CustomVariable(index=5, name='OSVersion', value=platform.platform(), scope=1))

    try:
        tracker.track_event(event, session, visitor)
    except:
        logging.debug("BAZARR unable to track event.")
        pass
    else:
        with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'analytics.dat')), 'w+') as handle:
            handle.write(codecs.encode(pickle.dumps(visitor), "base64").decode())