mirror of
https://github.com/morpheus65535/bazarr
synced 2024-12-24 16:52:06 +00:00
Fix for analytics under Python 3.x.
This commit is contained in:
parent
600ef3abc2
commit
2ecd21beb0
2 changed files with 11 additions and 7 deletions
|
@ -6,6 +6,8 @@ import base64
|
|||
import random
|
||||
import platform
|
||||
import os
|
||||
import logging
|
||||
import codecs
|
||||
|
||||
from pyga.requests import Event, Page, Tracker, Session, Visitor, Config
|
||||
from pyga.entities import CustomVariable
|
||||
|
@ -29,11 +31,11 @@ def track_event(category=None, action=None, label=None):
|
|||
|
||||
try:
|
||||
if settings.analytics.visitor:
|
||||
visitor = pickle.loads(base64.b64decode(settings.analytics.visitor), encoding='utf-8')
|
||||
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)
|
||||
visitor = pickle.loads(codecs.decode(settings.analytics.visitor.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)
|
||||
except:
|
||||
visitor = Visitor()
|
||||
visitor.unique_id = random.randint(0, 0x7fffffff)
|
||||
|
@ -56,8 +58,9 @@ def track_event(category=None, action=None, label=None):
|
|||
try:
|
||||
tracker.track_event(event, session, visitor)
|
||||
except:
|
||||
logging.debug("BAZARR unable to track event.")
|
||||
pass
|
||||
else:
|
||||
settings.analytics.visitor = base64.b64encode(pickle.dumps(visitor))
|
||||
settings.analytics.visitor = codecs.encode(pickle.dumps(visitor), "base64").decode()
|
||||
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
|
||||
settings.write(handle)
|
||||
|
|
|
@ -5,6 +5,7 @@ import calendar
|
|||
from math import floor
|
||||
from pyga.entities import Campaign, CustomVariable, Event, Item, Page, Session, SocialInteraction, Transaction, Visitor
|
||||
import pyga.utils as utils
|
||||
from six import itervalues
|
||||
try:
|
||||
from urllib import urlencode
|
||||
from urllib2 import Request as urllib_request
|
||||
|
@ -210,7 +211,7 @@ class Request(GIFRequest):
|
|||
x10.clear_key(self.X10_CUSTOMVAR_VALUE_PROJCT_ID)
|
||||
x10.clear_key(self.X10_CUSTOMVAR_SCOPE_PROJECT_ID)
|
||||
|
||||
for cvar in custom_vars.itervalues():
|
||||
for cvar in itervalues(custom_vars):
|
||||
name = utils.encode_uri_components(cvar.name)
|
||||
value = utils.encode_uri_components(cvar.value)
|
||||
x10.set_key(
|
||||
|
|
Loading…
Reference in a new issue