Beispiel #1
0
def setloginnum(uid):
    log = logging.getLogger('mylog')
    try:
        loginnum_info = LoginNum.objects.get(uid=uid)
        log.info("[setloginnum] before:uid=%d,login_num=%d,last_login=%s,last_request=%s",int(uid),loginnum_info.login_num,loginnum_info.last_login,loginnum_info.last_request)
        d = datetime.datetime.now().date() -  loginnum_info.last_login  
        if d.days == 1 and loginnum_info.login_num < 7:
            loginnum_info.login_num = loginnum_info.login_num + 1
            loginnum_info.last_login = datetime.datetime.now().date()
            loginnum_info.save()
            log.info("[setloginnum] continue login:uid=%d,login_num=%d,last_login=%s,last_request=%s",int(uid),loginnum_info.login_num,loginnum_info.last_login,loginnum_info.last_request)
        elif (d.days == 0):
            log.info("[setloginnum] repeat login:uid=%d",int(uid))
        else:
            loginnum_info.login_num =  1
            loginnum_info.last_login = datetime.datetime.now().date()
            loginnum_info.save()
            log.info("[setloginnum] interrupt login:uid=%d,login_num=%d,last_login=%s,last_request=%s",int(uid),loginnum_info.login_num,loginnum_info.last_login,loginnum_info.last_request)
        db.reset_queries() 
        return True
    except LoginNum.DoesNotExist,e:
        log.info("first login:uid=%d,last_login=%s,last_request=1970-01-01",int(uid),datetime.datetime.now().date())
        data = LoginNum(uid,1,datetime.datetime.now().date(),'1970-01-01')
        data.save()
        db.reset_queries() 
        return True
Beispiel #2
0
def findAnchorButton(request,uid,device_type):
    response =  OrderedDict()
    try:
        url="http://www.service.vip.yy.com/static/image/findanchorbutton/"
        inner_img =  {"android":url+"inner-3x.png",    \
                      "ios":url+"inner-2x.png"}
        outer_img = {} 
        user_props=vipdef.thriftFactory.execute(TTurnoverService, 'getUserPropsByPropId',int(uid),140075,TAppId.VipPk)
        log.info("[findAnchorButton] uid=%s,result=%s",uid,str(user_props))
        response['code'] = 0
        response['props_name'] = '荧光棒'
        response['props_id'] = 140075
        response['props_count'] = 0 
        for data in user_props:
            response['props_count'] = response['props_count'] + data.propsCount
        if response['props_count'] == 0 :
            outer_img =  {"android":url+"3x-no.png",    \
                          "ios":url+"2x-no.png"}
        else:
            outer_img =  {"android":url+"3x-01.png",    \
                          "ios":url+"2x-01.png"}
        for data in user_props:
            response['props_count'] = data.propsCount
            log.info("[findAnchorButton] uid=%d,propsId=%d,propsCount=%d",data.uid,data.propsId,data.propsCount)
        response['inner_img'] = inner_img[device_type]
        response['outer_img'] = outer_img[device_type]
        response['props_name'] = '荧光棒'
    except Exception, e:
        response['code'] = str(e)
Beispiel #3
0
def userinfo(request):
    response =  OrderedDict()
    try:
        #key = request.META['HTTP_KEY']
        #checktoken(request.data['uid'],key)
        log.info("[userinfo] data=%s",request.data)
        data = {}
        data["uid"] =int(request.data["uid"])
        data["stay_time"] = int(request.data["stay_time"])
        data['device_id'] = request.data["device_id"]
        data['last_modify'] = datetime.datetime.now()
        if  request.data.has_key('push_id'):
            data["push_id"] = request.data["push_id"]
        else:
            data["push_id"] = request.data["device_id"]
        user_infos = UserLoginInfo.objects.filter(push_id=data['push_id'])
        for temp in user_infos:
            temp.push_id=""
            temp.save()
        serializer = UserLoginInfoSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            response['result'] = 'success'
        else:
            user_stay = UserLoginInfo.objects.get(uid=request.data['uid'])
            if data['stay_time'] !=0:
                user_stay.stay_time=data['stay_time']
            user_stay.device_id=data['device_id']
            user_stay.push_id = data["push_id"]
            user_stay.last_modify = datetime.datetime.now()
            user_stay.save()
            response['result'] = 'success'
    except Exception,e:
        response['result'] = str(e)
Beispiel #4
0
def userstay(request):
    response =  OrderedDict()
    try:
        #key = request.META['HTTP_KEY']
        #checktoken(request.data['uid'],key)
        log.info("[userstay] data=%s",request.data)
        data = {}
        data["uid"] =int(request.data["uid"])
        data["stay_time"] = int(request.data["stay_time"])
        data['device_id'] = request.data["device_id"]
        data["push_id"] = request.data["device_id"]
        log.info("[userstay] uid=%d,device_id=%s,stay_time=%d",data["uid"],data["device_id"],data["stay_time"])
        data['last_modify'] = datetime.datetime.now()
        user_stays = UserStay.objects.filter(device_id=request.data['device_id'])
        #if user_stays.count() >=3:
        #    raise Exception("the device id out of limit")
        for temp in user_stays:
            temp.push_id=""
            temp.save()
        serializer = UserStaySerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            response['result'] = 'success'
        else:
            user_stay = UserStay.objects.get(uid=request.data['uid'])
            if data['stay_time'] !=0:
                user_stay.stay_time=data['stay_time']
            user_stay.device_id=data['device_id']
            user_stay.push_id = data["push_id"]
            user_stay.last_modify = datetime.datetime.now()
            user_stay.save()
            response['result'] = 'success'
    except Exception,e:
        response['result'] = str(e)
Beispiel #5
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)
Beispiel #6
0
def newhandguide(request):
    data = request.data
    user_id = int(data['uid'])
    version = data['version']
    sid = int(data['sid'])
    ssid = int(data['ssid'])
    '''
    if isinstance(data, dict):
        user_id = int(data['uid'])
        version = data['version']
        sid = int(data['sid'])
        ssid = int(data['ssid'])
    else:
        user_id = data['uid']
        version = data['version']
        sid = data['sid']
        ssid = data['ssid']
    '''
    response =  OrderedDict()
    propId = 140061
    appid = TAppId.VipPk
    expand = ''
    addType = 2
    activityId = 171
    useAfterAdd = True
    addSeqId =  version + '_' + str(user_id) 
    ret = 0
    try:
        #uid = request.META['HTTP_UID']
        #key = request.META['HTTP_KEY']
        #checktoken(uid,key)
        #if int(uid)<>int(request.data['uid']):
        #    raise Exception,"Permission Denied"
        log.info("[newhandguid] uid = %d",user_id)
        version_info = AppVersion.objects.get(version = version) 
        newhand_guid = NewhandGuide.objects.filter(uid = user_id,version = version)
        if newhand_guid.count() == 0:
            last_modify=datetime.datetime.now().date()
            data = NewhandGuide(uid=user_id,version=version,last_modify=last_modify)
            data.save()
            result=vipdef.thriftFactory.execute(TTurnoverService, 'addGiftBagActivity',user_id, propId,1, addSeqId, appid, addType, expand, sid, ssid, useAfterAdd, activityId)
        else:
            db.reset_queries() 
            response['result'] = 'repeat'
            json= JSONRenderer().render(response)
            return HttpResponse(json)
        if result==1:
            response['result'] = 'success'
        else:
            response['result'] = 'failed'
    except AppVersion.DoesNotExist,e:
         response['result'] = 'invalid verison'
Beispiel #7
0
def createtoken(uid):
    try:  
        log.info("[createtoken] uid=%s",uid)
        user = User.objects.get(username = uid)
        if user:
            token,created = Token.objects.get_or_create(user=user)
            if not created:
                key = default_token_generator.make_token(user)
                created = datetime.datetime.now()
                Token.objects.filter(user=user).update(key=key,created=created)
                return key
            return token.key
        else:
            return "not user"
    except Exception, e:  
        return str(e)
Beispiel #8
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)
Beispiel #9
0
def login(request,uid):
    response = OrderedDict()
    log.info("[login] uid=%s",uid)
    try:
        m = re.match(r'(^\d{1,11}$)',uid)
        if m is None:
            raise Exception,"invalid argument:uid" 
        setloginnum(uid)
        user = User.objects.get(username=uid)
        user.last_login = datetime.datetime.now()
        user.save()
        response['result'] = 'success'
    except User.DoesNotExist, e :
        user = User(id=uid,username=uid,   \
                    password='', \
                    is_staff=1,is_active=1,is_superuser=0)
        user.save()
        key = createtoken(uid)
        response['result'] = 'success'
Beispiel #10
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
Beispiel #11
0
def addmobilestar(request):
    data = request.data
    uid = int(data['uid'])
    count = int(data['count'])
    sid = int(data['sid'])
    ssid = int(data['ssid'])
    user_props = {}
    user_props["uid"] = uid
    user_props["propid"] = 140066
    user_props["amount"] = count
    user_props["type"] = 2
    log.info("[addmobilestar] data=%s",str(data))
    response =  OrderedDict()
    addSeqId = str(uid) + "_" + str(time.time()) 
    ret = 0
    try:
        key = request.META['HTTP_KEY']
        checktoken(uid,key.strip())
        #if int(uid)<>int(request.data['uid']):
        #    raise Exception,"Permission Denied"
        prop_amount = UserProps.objects.filter(uid=uid,type=2,last_modify__gt=datetime.datetime.now().date()).aggregate(Sum("amount"))
        if prop_amount['amount__sum']>=30:
            raise Exception,"out of limit"
        #ret = add_mobilestar_props(uid,sid,ssid,count,addSeqId)
        propId = 140066
        appid = TAppId.VipPk
        expand = ''
        addType = 2
        activityId = 177
        useAfterAdd = False
        ret=vipdef.thriftFactory.execute(TTurnoverService, 'addGiftBagActivity',uid, propId, count, addSeqId, appid, addType, expand, sid, ssid, useAfterAdd, activityId)
        if ret==1:
            serializer = UserPropsSerializer(data=user_props)
            if serializer.is_valid():
                serializer.save()
            response['result'] = 'success'
        else:
            response['result'] = 'failed'
    except AppVersion.DoesNotExist,e:
         response['result'] = 'invalid verison'
Beispiel #12
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)
Beispiel #13
0
def updateloginnum(request,uid,loginnum,last_login):
    response =  OrderedDict()
    try:
        log.info(" [updateloginnum]request:uid=%d,login_num=%d,last_login=%s,last_request=%s",int(uid),int(loginnum),last_login)
        loginnum_info = LoginNum.objects.get(uid=uid)
        log.info(" [updateloginnum] before:uid=%d,login_num=%d,last_login=%s,last_request=%s",int(uid),loginnum_info.login_num,loginnum_info.last_login,loginnum_info.last_request)
        loginnum_info.login_num = loginnum 
        loginnum_info.last_login = last_login
        loginnum_info.last_request = '1970-01-01'
        loginnum_info.save()
        response['result'] = 'success'
    except LoginNum.DoesNotExist,e:
        log.info("first login:uid=%d,last_login=%s,last_request=1970-01-01",int(uid),datetime.datetime.now().date())
        data = LoginNum(uid,loginnum,last_login,'1970-01-01')
        data.save()
        response['result'] = 'success'
Beispiel #14
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)
Beispiel #15
0
            log.info("[setloginnum] repeat login:uid=%d",int(uid))
        else:
            loginnum_info.login_num =  1
            loginnum_info.last_login = datetime.datetime.now().date()
            loginnum_info.save()
            log.info("[setloginnum] interrupt login:uid=%d,login_num=%d,last_login=%s,last_request=%s",int(uid),loginnum_info.login_num,loginnum_info.last_login,loginnum_info.last_request)
        db.reset_queries() 
        return True
    except LoginNum.DoesNotExist,e:
        log.info("first login:uid=%d,last_login=%s,last_request=1970-01-01",int(uid),datetime.datetime.now().date())
        data = LoginNum(uid,1,datetime.datetime.now().date(),'1970-01-01')
        data.save()
        db.reset_queries() 
        return True
    except Exception, e:
        log.info("error=%s",str(e))
        db.reset_queries() 
        return False

@api_view()
def login(request,uid):
    response = OrderedDict()
    log.info("[login] uid=%s",uid)
    try:
        m = re.match(r'(^\d{1,11}$)',uid)
        if m is None:
            raise Exception,"invalid argument:uid" 
        setloginnum(uid)
        user = User.objects.get(username=uid)
        user.last_login = datetime.datetime.now()
        user.save()