# Conflicts: # bazarr/get_subtitle.py # bazarr/main.py # bazarr/utils.pypull/543/head
commit
1b4e4e1495
@ -0,0 +1,52 @@
|
||||
# coding=utf-8
|
||||
|
||||
import cPickle as pickle
|
||||
import base64
|
||||
import random
|
||||
import platform
|
||||
import os
|
||||
|
||||
from pyga.requests import Event, Page, Tracker, Session, Visitor, Config
|
||||
from pyga.entities import CustomVariable
|
||||
|
||||
from get_args import args
|
||||
from config import settings
|
||||
from utils import get_sonarr_version, get_radarr_version
|
||||
|
||||
sonarr_version = get_sonarr_version()
|
||||
radarr_version = get_radarr_version()
|
||||
|
||||
|
||||
def track_event(category=None, action=None, label=None):
|
||||
if not settings.analytics.getboolean('enabled'):
|
||||
print "no analytics"
|
||||
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))
|
||||
tracker.add_custom_variable(CustomVariable(index=3, name='SonarrVersion', value=sonarr_version, scope=1))
|
||||
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))
|
||||
tracker.track_event(event, session, visitor)
|
||||
tracker.track_pageview(page, session, visitor)
|
||||
|
||||
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)
|
Loading…
Reference in new issue