Ejemplo n.º 1
0
def changeFullScreenAdDate(test):
    #print int(time.strftime('%Y%m%d', time.localtime(time.time()-7201)))
    try:
        redis = redisFactory('/data/services/common-conf/redis_conf.yml')
        cli = redis.get("app_yypk")
        sid = cli.get('fullScreenAd_sid')
        print "changeFullScreenAdDate redis", sid
        if sid != None:
            log.info("[changeFullScreenAdDate] redis sid:%ld", int(sid))
            return sid
        result = vipdef.thriftBinaryFactory.execute(VipPkThriftRead, 'GetLogicPkActRank', 15, 0, int(time.strftime('%Y%m%d', time.localtime(time.time()-7201-86400))), -1, 0, 1)

        print "changeFullScreenAdDate len", len(result)
        if len(result) > 0:
            print "changeFullScreenAdDate support:", result[0].support
            sid = result[0].uid
            '''
            if result[0].support < 1000000:
                sid = -1
            else:
                sid = result[0].uid
           '''
            log.info("[changeFullScreenAdDate] sid:%ld", sid)
            print "changeFullScreenAdDate sid", sid
            #print "changeFullScreenAdDate uid", result[0].uid
            # 是否存在,否则取默认的
            cli.setex('fullScreenAd_sid', str(sid), int(60))
        else:
            log.info("[changeFullScreenAdDate] empty sid!")
            sid = -1
            cli.setex('fullScreenAd_sid', str(sid), int(30))
        return sid
    except Exception, e:
        print "changeFullScreenAdDate: %s" % str(e)
        return 0
Ejemplo n.º 2
0
def newsTap(request,news_type):
    response = OrderedDict()
    try:
        m_type = 7 
        s_type = news_type
        config_id = 0
        redis_key = "loadAppConfig_"+str(m_type)+"_"+str(s_type)+"_"+str(config_id);
        redis = redisFactory('/data/services/common-conf/redis_conf.yml')
        cli = redis.get("app_yypk")
        if None != cli.get(redis_key) :
            js = str(cli.get(redis_key))
            log.info("[newsTap] redis key:%s val:%s", redis_key, js)
            return HttpResponse(js)

        li = []
        if config_id > 0:
            li = CommonAppConfig.objects.filter(m_type=m_type,s_type=s_type,config_id = config_id,end_time__gt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())),beg_time__lt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))).order_by('beg_time')
        else:
            li = CommonAppConfig.objects.filter(m_type=m_type,s_type=s_type,end_time__gt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())),beg_time__lt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))).order_by('beg_time')
        log.info("[newsTap] size:%u", len(li))
        js = li[0].json_data
        cli.setex(redis_key, str(js), int(60))

    except Exception, e:
        response['code'] = -1
        response['copywriter'] = ''
        response['sid'] = 80000
        response['ssid'] = 0
        response['head_url'] = ''
        response['nick'] = '小蕊'
        js = JSONRenderer().render(response)
Ejemplo n.º 3
0
def fullScreenAd(request,device_type):
    #changeFullScreenAdDate('test')
    response = OrderedDict()
    try:
        m_type = 10 
        s_type = 0 
        if device_type=="android":
            s_type = 2
        elif device_type=="ios":
            s_type = 1
        config_id = 0
        redis = redisFactory('/data/services/common-conf/redis_conf.yml')
        cli = redis.get("app_yypk")
        '''config_id = cli.get("fullScreenAd_sid")
        if int(config_id) == -1:
            # 缓存config_id == -1 没有达到200wPK值
            response['code'] = '-1'
            response['is_display'] = 0
            json= JSONRenderer().render(response)
            return HttpResponse(json)
        elif config_id == None:
            #config_id = changeFullScreenAdDate('test')
            if config_id == None:
                config_id = 0
        '''

        redis_key = "loadAppConfig_"+str(m_type)+"_"+str(s_type)+"_"+str(config_id);
        if None != cli.get(redis_key) :
            js = str(cli.get(redis_key))
            log.info("[fullScreenAd] redis key:%s val:%s", redis_key, js)
            return HttpResponse(js)

        li = []
        if config_id > 0:
            li = CommonAppConfig.objects.filter(m_type=m_type,s_type=s_type,config_id = config_id,end_time__gt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())),beg_time__lt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))).order_by('beg_time')
        else:
            li = CommonAppConfig.objects.filter(m_type=m_type,s_type=s_type,end_time__gt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())),beg_time__lt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))).order_by('beg_time')
        log.info("[fullScreenAd] size:%u", len(li))
        if len(li) > 0:
            js = li[0].json_data
        else:
            js = '{"code":"0","is_display":0}'
        cli.setex(redis_key, str(js), int(60))

    except Exception, e:
        response['code'] = str(e)
        js = JSONRenderer().render(response)
Ejemplo n.º 4
0
def operatingAd(request):
    response = {}
    js = None
    try:
        response['code'] = 0
        redis = redisFactory('/data/services/common-conf/redis_conf.yml')
        cli = redis.get("app_yypk")
        jump_data = {}
        # 判断是否有缓存
        redis_key = "operatingAd_info"
        if None != cli.get(redis_key) and False != cli.get(redis_key):
            log.info("[operatingAd] redis")
            js = cli.get(redis_key)
            log.info("[operatingAd] redis key:%s val:%s", redis_key, js)

            """response['image'] = cli.get("operatingAd_image")
            jump_data["type"] = int(cli.get("operatingAd_type"))
            jump_data["target"] = cli.get("operatingAd_target")
            response['title'] = cli.get("operatingAd_title")"""
        else:
            log.info("[operatingAd] mysql")
            # 访问数据库
            print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
            li = CommonAppConfig.objects.filter(m_type=1).filter(end_time__gt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))).filter(beg_time__lt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))).order_by('beg_time')
            #li = CommonAppConfig.objects.filter(beg_time__gt = '2016-08-30 15:51:00')
            #print len(li)
            log.info("[operatingAd] mysql size:%d", int(len(li)))
            if len(li) == 0:
                log.info("[operatingAd] empty")
                response['code'] = -1
            else:

                cli.setex(redis_key, str(li[0].json_data), int(60))
                log.info("[operatingAd] key:%s val:%s",  redis_key,  li[0].json_data)
                js = li[0].json_data

    except Exception, e:
        response['code'] = -1
        response['msg'] = str(e)
        js = JSONRenderer().render(response)
Ejemplo n.º 5
0
def loadAppConfig(request):
    response = OrderedDict()
    try:
        m_type = 0
        s_type = 0
        config_id = 0
        if request.GET.get('m_type') != None:
            m_type = int(request.GET.get('m_type'))
        if request.GET.get('s_type') != None:
            s_type = int(request.GET.get('s_type'))
        if request.GET.get('config_id') != None:
            config_id = int(request.GET.get('config_id'))
        redis_key = "loadAppConfig_"+str(m_type)+"_"+str(s_type)+"_"+str(config_id);
        redis = redisFactory('/data/services/common-conf/redis_conf.yml')
        cli = redis.get("app_yypk")
        if None != cli.get(redis_key) :
            js = str(cli.get(redis_key))
            log.info("[loadAppConfig] redis key:%s val:%s", redis_key, js)
            return HttpResponse(js)

        li = []
        if config_id > 0:
            li = CommonAppConfig.objects.filter(m_type=m_type,s_type=s_type,config_id = config_id,end_time__gt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())),beg_time__lt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))).order_by('beg_time')
        else:
            li = CommonAppConfig.objects.filter(m_type=m_type,s_type=s_type,end_time__gt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())),beg_time__lt = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))).order_by('beg_time')
        log.info("[loadAppConfig] size:%u", len(li))
        data = []
        for item in li:
            print item.json_data
            data.append(json.loads(item.json_data))
        print data
        response["code"] = 0
        response["data"] = data
        js = JSONRenderer().render(response)
        cli.setex(redis_key, str(js), int(60))
    except Exception, e:
        response['code'] = str(e)
        response['data'] = []
        js = JSONRenderer().render(response)