Ejemplo n.º 1
0
def make_visitor():
    from pyga.requests import Visitor

    info = lambda x: xbmc.getInfoLabel("System.%s" % x)
    visitor = Visitor()
    visitor.user_agent = get_user_agent()
    visitor.locale = xbmc.getLanguage()
    visitor.screen_resolution = "%sx%s" % (info("ScreenWidth"), info("ScreenHeight"))
    return visitor
Ejemplo n.º 2
0
def make_visitor():
    from pyga.requests import Visitor

    info = lambda x: xbmc.getInfoLabel("System.%s" % x)
    visitor = Visitor()
    visitor.user_agent = get_user_agent()
    visitor.locale = xbmc.getLanguage()
    visitor.screen_resolution = "%sx%s" % (info("ScreenWidth"),
                                           info("ScreenHeight"))
    return visitor
Ejemplo n.º 3
0
def log_traffic(request):
    if not google_analytics:
        return
    url = urlparse(request.base_url)

    pyga_tracker = Tracker(google_analytics, url.hostname)

    pyga_visitor = Visitor()
    pyga_visitor.ip_address = request.access_route[0]
    pyga_visitor.user_agent = request.headers.get('User-Agent')
    user_locals = []
    if 'Accept-Language' in request.headers:
        al = request.headers.get('Accept-Language')
        if al is not None:
            matched_locales = utils.validate_locale(al)
            if matched_locales:
                lang_lst = map((lambda x: x.replace('-', '_')),
                               (i[1] for i in matched_locales))
                quality_lst = map(
                    (lambda x: x and x or 1),
                    (float(i[4] and i[4] or '0') for i in matched_locales))
                lang_quality_map = map((lambda x, y: (x, y)), lang_lst,
                                       quality_lst)
                user_locals = [
                    x[0] for x in sorted(
                        lang_quality_map, key=itemgetter(1), reverse=True)
                ]
    if user_locals:
        pyga_visitor.locale = user_locals[0]

    pyga_session = Session()

    pyga_page = Page(url.path)
    pyga_page.referrer = request.headers.get('Referer')

    logger.info('Logging GA traffic from %s to host %s with page %s',
                pyga_visitor.ip_address, url.hostname, url.path)

    try:
        pyga_tracker.track_pageview(pyga_page, pyga_session, pyga_visitor)
    except URLError:
        logger.warn('Unable to connect to analytics')
    except:
        logger.error('Analytics logging failed')
        logger.error(sys.exc_info())
Ejemplo n.º 4
0
Archivo: ga.py Proyecto: dizzelk/Stream
def make_visitor():
    from pyga.requests import Visitor
    visitor = Visitor()
    visitor.user_agent = get_user_agent()
    visitor.locale = xbmc.getLanguage()
    return visitor
Ejemplo n.º 5
0
def make_visitor():
    from pyga.requests import Visitor
    visitor = Visitor()
    visitor.user_agent = get_user_agent()
    visitor.locale = xbmc.getLanguage()
    return visitor
Ejemplo n.º 6
0
    uniq_id=random.random()*time.time()
    Addon.setSetting('uniq_id', str(uniq_id))

GAcookie =Addon.getSetting('GAcookie')
uniq_id=Addon.getSetting('uniq_id')

ses_file = xbmc.translatePath('special://temp/'+ 'session.ag')
vis_file = xbmc.translatePath('special://temp/'+ 'visitor.ag')
try:
    with open(vis_file, 'rb') as f:
        visitor = pickle.load(f)

except: 
    visitor = Visitor()
    visitor.user_agent=get_user_agent()
    visitor.locale = xbmc.getLanguage()
    info = lambda x: xbmc.getInfoLabel("System.%s" % x)
    visitor.screen_resolution = "%sx%s" % (info("ScreenWidth"), info("ScreenHeight"))
    visitor.unique_id=random.randint(0, 0x7fffffff)

    with open(vis_file, 'wb') as f:
        pickle.dump(visitor, f)
       
try:
    with open(ses_file, 'rb') as f:
        session = pickle.load(f)

except: 
    session = Session()
    with open(ses_file, 'wb') as f:
        pickle.dump(session, f)