mirror of
https://github.com/morpheus65535/bazarr
synced 2024-12-25 17:17:12 +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 random
|
||||||
import platform
|
import platform
|
||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
|
import codecs
|
||||||
|
|
||||||
from pyga.requests import Event, Page, Tracker, Session, Visitor, Config
|
from pyga.requests import Event, Page, Tracker, Session, Visitor, Config
|
||||||
from pyga.entities import CustomVariable
|
from pyga.entities import CustomVariable
|
||||||
|
@ -29,7 +31,7 @@ def track_event(category=None, action=None, label=None):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if settings.analytics.visitor:
|
if settings.analytics.visitor:
|
||||||
visitor = pickle.loads(base64.b64decode(settings.analytics.visitor), encoding='utf-8')
|
visitor = pickle.loads(codecs.decode(settings.analytics.visitor.encode(), "base64"))
|
||||||
if visitor.user_agent is None:
|
if visitor.user_agent is None:
|
||||||
visitor.user_agent = os.environ.get("SZ_USER_AGENT")
|
visitor.user_agent = os.environ.get("SZ_USER_AGENT")
|
||||||
if visitor.unique_id > int(0x7fffffff):
|
if visitor.unique_id > int(0x7fffffff):
|
||||||
|
@ -56,8 +58,9 @@ def track_event(category=None, action=None, label=None):
|
||||||
try:
|
try:
|
||||||
tracker.track_event(event, session, visitor)
|
tracker.track_event(event, session, visitor)
|
||||||
except:
|
except:
|
||||||
|
logging.debug("BAZARR unable to track event.")
|
||||||
pass
|
pass
|
||||||
else:
|
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:
|
with open(os.path.join(args.config_dir, 'config', 'config.ini'), 'w+') as handle:
|
||||||
settings.write(handle)
|
settings.write(handle)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import calendar
|
||||||
from math import floor
|
from math import floor
|
||||||
from pyga.entities import Campaign, CustomVariable, Event, Item, Page, Session, SocialInteraction, Transaction, Visitor
|
from pyga.entities import Campaign, CustomVariable, Event, Item, Page, Session, SocialInteraction, Transaction, Visitor
|
||||||
import pyga.utils as utils
|
import pyga.utils as utils
|
||||||
|
from six import itervalues
|
||||||
try:
|
try:
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
from urllib2 import Request as urllib_request
|
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_VALUE_PROJCT_ID)
|
||||||
x10.clear_key(self.X10_CUSTOMVAR_SCOPE_PROJECT_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)
|
name = utils.encode_uri_components(cvar.name)
|
||||||
value = utils.encode_uri_components(cvar.value)
|
value = utils.encode_uri_components(cvar.value)
|
||||||
x10.set_key(
|
x10.set_key(
|
||||||
|
|
Loading…
Reference in a new issue