sergy22051988
Новичок
Здравствуйте, не могу запустить мод для WoT, может кто поможет разобраться с кодом для google-analytics.com
Код:
import BigWorld, urllib, urllib2, constants, threading
from helpers import dependency
from helpers import getLanguageCode
from skeletons.connection_mgr import IConnectionManager
connectionManager = dependency.instance(IConnectionManager)
Language = getLanguageCode()
class Analytics(object):
def __init__(self, tid, name, ver, SDK_Ver, config = 'default'):
self.tid = tid
self.name = name
self.ver = '%s SDK:%s' % (ver, SDK_Ver)
self.config = config
self.lang = Language.upper()
connectionManager.onLoggedOn += self.Start
connectionManager.onDisconnected += self.End
def Send(self, mode = 'start'):
url = 'http://www.google-analytics.com/collect'
param = urllib.urlencode({
'sc': mode,
'v': 1,
'tid': self.tid,
'cid': self.ID,
't': 'screenview',
'an': self.name,
'av': self.ver,
'cd': '%s-%s' % (constants.AUTH_REALM, self.lang),
'ul': self.lang,
'aid': self.config
})
try:
req = urllib2.Request(url, param, headers={'User-Agent': '%s/%s' % (self.name, self.ver)})
resp = urllib2.urlopen(req, timeout=3).read()
except:
BigWorld.logWarning(self.name, 'Unable to send data analytics', None)
def Start(self, data):
self.ID = data['token2'].split(':')[0]
if int(self.ID) in BlackList:
BigWorld.logWarning(self.name, 'Unfortunately, due to hardware incompatibility, further work is impossible!', None)
BigWorld.quit()
threading.Thread(target = self.Send).start()
def End(self):
self.Send('end')
Последнее редактирование модератором: