예제 #1
0
 def DELETE(self, cid, goodsid):
     ''' /bfdrest/client/(cid)/goods/(goodsid) '''
     myuuid = uuid.uuid1()
     LOG("info", _myuuid=myuuid)
     data = web.input()
     jdata = data
     ret = {}
     g_str = cache.get('%s:Goods:%s' % (cid, goodsid))
     pgs = RecBanner_pb2.Goods()
     if g_str:
         pgs.ParseFromString(g_str)
         if not pgs.is_ranges:
             rm_goods_solr(cid, goodsid)
     cache.delete('%s:Goods:%s' % (cid, goodsid))
     remove_goods_relation(cid, goodsid, jdata)
     goods_list = cache.get('%s:Goods:_all_' % cid)
     if goods_list:
         goods_list = json.loads(goods_list)
     else:
         goods_list = {}
     if goodsid in goods_list:
         del goods_list[goodsid]
         cache.set('%s:Goods:_all_' % cid, json.dumps(goods_list))
     ret['success'] = True
     return pub.callback(json.dumps(ret), myuuid)
예제 #2
0
    def GET(self, cid, cat, method=None):
        '''  
            /bfdrest/client/(cid)/category/(cat)/all for get all children;
            /bfdrest/client/(cid)/category/(cat) for get category's child;
            /bfdrest/client/Czouxiu/category/_all_(/all) for example;
        '''
        myuuid = uuid.uuid1()
        LOG("info", _myuuid=myuuid)

        #print('cid:%s,cat:%s,method;%s' %(cid,cat,method))
        def faild(info):
            ret = copy.deepcopy(GET_ret_template)
            ret['success'] = False
            ret['error_info'] = info
            return json.dumps(ret)

        tree_path = cat.split(':')
        if tree_path[0] != "_all_":
            return pub.callback(faild('No such category'), myuuid)
        if cid not in client_property_tree:
            try:
                client_property_tree[cid] = cPickle.load(
                    open('./data/%s.ptree.pkl' % cid, 'rb'))
            except:
                client_property_tree[cid] = {"nodes": {}}
        path_str = 'client_property_tree["%s"]' % cid
        for node in tree_path[1:]:
            path_str += '["nodes"][u"%s"]' % node
        try:
            #print path_str
            cur_node = eval(path_str)
        except Exception, e:
            err_info = 'No such category. key error: %s' % unicode(
                e.message).encode("utf-8")
            return pub.callback(faild(err_info), myuuid)
예제 #3
0
    def GET(self, cid, goodsid=None, range=None):
        ''' /bfdrest/client/(cid)/goods/(goodsid)/(items) '''
        myuuid = uuid.uuid1()
        LOG("info", _myuuid=myuuid)
        if goodsid == None:
            if cid in goods_fields_conf:
                return pub.callback(json.dumps(goods_fields_conf[cid]), myuuid)
            return pub.callback(json.dumps(goods_fields), myuuid)
        elif goodsid == "type":
            return pub.callback(json.dumps(type_define), myuuid)
        else:
            gv = cache.get('%s:Goods:%s' % (cid, goodsid))
            if gv:
                ret = json.loads(gv)
                ret['success'] = True
                if range == None:
                    if 'keys' in ret:
                        del ret['keys']
                        pass
                    return pub.callback(json.dumps(ret), myuuid)
                else:
                    iids = []
                    # 获取范围的item
                    for key in [goodsid]:
                        ids_str = cache.get('%s:GoodsItems:%s' % (cid, key))
                        if ids_str:
                            iids.extend(json.loads(ids_str))
                    return pub.callback(json.dumps(iids), myuuid)

            else:
                ret = {}
                ret['success'] = False
                ret['error_info'] = 'no such goods id.'
                return pub.callback(json.dumps(ret), myuuid)
예제 #4
0
 def POST(self, cid, abid, method=None):
     ''' '/bfdrest/client/(cid)/ABtest/(abid)' '''
     myuuid = uuid.uuid1()
     LOG("info", _myuuid=myuuid)
     stop = False
     if method == "stop":
         stop = True
     data = web.data()
     ret = {}
     rv = json.loads(data)
     if not SetBannerABtest(cid, abid, rv, stop):
         ret["success"] = False
         ret["error_info"] = "can't save banner abtest."
         return pub.callback(json.dumps(ret), myuuid)
     rlist = cache.get('%s:ABtest:_all_' % cid)
     if rlist:
         rlist = json.loads(rlist)
     else:
         rlist = {}
     rlist[abid] = time.time()
     rstr = cache.set('%s:ABtest:_all_' % (cid), json.dumps(rlist))
     rstr = cache.set('%s:ABtest:%s' % (cid, abid), data)
     if rstr:
         ret["success"] = True
     else:
         ret["success"] = False
         ret["error_info"] = "can't save abtest rule."
     return pub.callback(json.dumps(ret), myuuid)
예제 #5
0
 def DELETE(self, cid, abid):
     ''' '/bfdrest/client/(cid)/ABtest/(abid)' '''
     myuuid = uuid.uuid1()
     LOG("info", _myuuid=myuuid)
     data = web.input()
     rv = data
     ret = {}
     if not SetBannerABtest(cid, abid, rv, False, True):
         ret["success"] = False
         ret["error_info"] = "can't delete banner abtest."
         return pub.callback(json.dumps(ret), myuuid)
     rlist = cache.get('%s:ABtest:_all_' % cid)
     if rlist:
         rlist = json.loads(rlist)
     else:
         rlist = {}
     if abid in rlist:
         del rlist[abid]
     rstr = cache.set('%s:ABtest:_all_' % (cid), json.dumps(rlist))
     rstr = cache.delete('%s:ABtest:%s' % (cid, abid))
     rstr = cache.delete('%s:ABtestRule:%s' % (cid, abid))
     if rstr:
         ret["success"] = True
     else:
         ret["success"] = True
         ret["error_info"] = "can't delete abtest rule."
     return pub.callback(json.dumps(ret), myuuid)
예제 #6
0
 def POST(self, cid, rid):
     ''' '/bfdrest/client/(cid)/operationrules/(rid)' '''
     myuuid = uuid.uuid1()
     LOG("info", _myuuid=myuuid)
     data = web.data()
     rv = json.loads(data)
     range_iids = {}
     #range_iids = goods.generalize_ranges(cid,rv["rec_ranges"])
     riids = []
     for key in range_iids:
         riids.extend(range_iids[key])
     operation_rule = ParseFromJson(rv)
     operation_rule.operation_rule_id = rid
     rlist = cache.get('%s:OperatorRules:_all_' % cid)
     if rlist:
         rlist = json.loads(rlist)
     else:
         rlist = {}
     rlist[rid] = time.time()
     cache.set('%s:OperatorRules:_all_' % (cid), json.dumps(rlist))
     cache.set('%s:OperationRule:%s' % (cid, rid),
               operation_rule.SerializeToString())
     rstr = cache.set('%s:OperatorRules:%s' % (cid, rid), data)
     ret = {}
     if rstr:
         ret["success"] = True
     else:
         ret["success"] = False
         ret["error_info"] = "can't save operation rule."
     return pub.callback(json.dumps(ret), myuuid)
예제 #7
0
 def GET(self, host, table, key, family, column, proto=None):
     ''' /bfdrest/bfdhabase2/host/table/key/family/column(/proto) for get key;
     '''
     myuuid = uuid.uuid1()
     LOG("info", _myuuid=myuuid)
     v = libhbase.get_column(key, family, column, host, table)
     if not v:
         return pub.callback(v, myuuid)
     if proto:
         ib = eval("%s()" % proto)
         try:
             ib.ParseFromString(v)
         except Exception, e:
             return pub.callback(str(e), myuuid)
         return pub.callback(json.dumps(proto2json(ib)), myuuid)
예제 #8
0
 def GET(self, cid, bid=None):
     ''' '/bfdrest/client/(cid)/banners','/bfdrest/client/(cid)/banners/(bid)' '''
     myuuid = uuid.uuid1()
     LOG("info", _myuuid=myuuid)
     if bid == None:
         return pub.callback(json.dumps(GET_ret), myuuid)
     else:
         rstr = cache.get('%s:Banners:%s' % (cid, bid))
         ret = {}
         if rstr:
             ret = json.loads(rstr)
             ret["success"] = True
         else:
             ret["success"] = False
             ret["error_info"] = "no such banner id."
         return pub.callback(json.dumps(ret), myuuid)
예제 #9
0
 def GET(self, cid, rid=None):
     ''' '/bfdrest/client/(cid)/operationrules','/bfdrest/client/(cid)/operationrules/(rid)' '''
     myuuid = uuid.uuid1()
     LOG("info", _myuuid=myuuid)
     if rid == None:
         return pub.callback(json.dumps(GET_ret), myuuid)
     else:
         rstr = cache.get('%s:OperatorRules:%s' % (cid, rid))
         ret = {}
         if rstr:
             ret = json.loads(rstr)
             ret["success"] = True
         else:
             ret["success"] = False
             ret["error_info"] = "no such operation rule."
         return pub.callback(json.dumps(ret), myuuid)
예제 #10
0
파일: bfdcache.py 프로젝트: emeitu/test
 def GET(self, n, b, k, proto=None):
     ''' /bfdrest/bfdcache/namesapce/business/key for get key;
     '''
     myuuid = uuid.uuid1()
     LOG("info", _myuuid=myuuid)
     v = cache.get(k, n, b)
     #        print '%s\t%s\t%s' % (n,b,k)
     if proto:
         if proto == 'DELETE':
             return pub.callback(json.dumps(cache.delete(k, n, b)), myuuid)
         if v == None or v == 'None':
             return pub.callback(json.dumps({}), myuuid)
         ib = eval("%s()" % proto)
         try:
             ib.ParseFromString(v)
         except Exception, e:
             return pub.callback(str(e), myuuid)
         return pub.callback(json.dumps(proto2json(ib)), myuuid)
예제 #11
0
 def GET(self, cid, abid=None):
     ''' '/bfdrest/client/(cid)/ABtest','/bfdrest/client/(cid)/ABtest/(ABid)' '''
     myuuid = uuid.uuid1()
     LOG("info", _myuuid=myuuid)
     if abid == None:
         return pub.callback(json.dumps(GET_ret), myuuid)
     else:
         rstr = cache.get('%s:ABtest:%s' % (cid, abid))
         if abid == "_all_":
             return rstr
         ret = {}
         if rstr:
             ret = json.loads(rstr)
             ret["success"] = True
         else:
             ret["success"] = False
             ret["error_info"] = "no such ABtest id."
         return pub.callback(json.dumps(ret), myuuid)
예제 #12
0
 def GET(self, path):
     ''' /bfdrest/bfdzk/zkpath;
     '''
     myuuid = uuid.uuid1()
     LOG("info", _myuuid=myuuid)
     ret = {}
     try:
         data = zk.get(path)
         try:
             data = json.loads(data)
         except:
             pass
         ret['data'] = data
         ret['children'] = zk.get_children(path)
     except:
         pass
     if len(ret) == 0: ret = None
     return pub.callback(json.dumps(ret), myuuid)
예제 #13
0
 def POST(self, cid, goodsid):
     ''' /bfdrest/client/(cid)/goods/(goodsid) '''
     myuuid = uuid.uuid1()
     LOG("info", _myuuid=myuuid)
     value = web.data()
     put_value = {}
     ret = {}
     data = {}
     pgs = RecBanner_pb2.Goods()
     g_str = cache.get('%s:Goods:%s' % (cid, goodsid))
     if g_str:
         pgs.ParseFromString(g_str)
     pgs.goods_id = goodsid
     try:
         put_value = json.loads(value)
     except Exception, e:
         ret["success"] = False
         ret["error_info"] = "wrong json format: %s" % str(e)
         return pub.callback(json.dumps(ret), myuuid)
예제 #14
0
 def DELETE(self, cid, bid):
     ''' '/bfdrest/client/(cid)/banners/(bid)' '''
     myuuid = uuid.uuid1()
     LOG("info", _myuuid=myuuid)
     rlist = cache.get('%s:Banners:_all_' % cid)
     if rlist:
         rlist = json.loads(rlist)
     else:
         rlist = {}
     if bid in rlist:
         del rlist[bid]
     cache.set('%s:Banners:_all_' % (cid), json.dumps(rlist))
     rstr = cache.delete('%s:Banners:%s' % (cid, bid))
     rstr = cache.delete('%s:RecBanner:%s' % (cid, bid))
     ret = {}
     if rstr:
         ret["success"] = True
     else:
         ret["success"] = False
         ret["error_info"] = "can't delete banner info."
     return pub.callback(json.dumps(ret), myuuid)
예제 #15
0
 def POST(self, cid, bid):
     ''' '/bfdrest/client/(cid)/banners/(bid)' '''
     myuuid = uuid.uuid1()
     LOG("info", _myuuid=myuuid)
     data = web.data()
     ret = {}
     rv = json.loads(data)
     rec_banner = ParseFromJson(cid, bid, rv)
     rlist = cache.get('%s:Banners:_all_' % cid)
     if rlist:
         rlist = json.loads(rlist)
     else:
         rlist = {}
     rlist[bid] = time.time()
     rstr = cache.set('%s:Banners:_all_' % (cid), json.dumps(rlist))
     rstr = cache.set('%s:RecBanner:%s' % (cid, bid),
                      rec_banner.SerializeToString())
     rstr = cache.set('%s:Banners:%s' % (cid, bid), data)
     if rstr:
         ret["success"] = True
     else:
         ret["success"] = False
         ret["error_info"] = "can't save banner info."
     return pub.callback(json.dumps(ret), myuuid)
예제 #16
0
 def DELETE(self, cid, rid):
     ''' '/bfdrest/client/(cid)/operationrules/(rid)' '''
     myuuid = uuid.uuid1()
     LOG("info", _myuuid=myuuid)
     data = web.input()
     jdata = data
     rstr = cache.delete('%s:OperationRule:%s' % (cid, rid))
     rstr = cache.delete('%s:OperatorRules:%s' % (cid, rid))
     rlist = cache.get('%s:OperatorRules:_all_' % cid)
     if rlist:
         rlist = json.loads(rlist)
     else:
         rlist = {}
     if rid in rlist:
         del rlist[rid]
     cache.delete('%s:OperatorRulesItems:%s' % (cid, rid))
     rstr = cache.set('%s:OperatorRules:_all_' % (cid), json.dumps(rlist))
     for p_bid in json.loads(jdata["banner_id"]):
         p_bid_str = cache.get("%s:RecBanner:%s" % (cid, p_bid))
         p_banner = RecBanner_pb2.RecBanner()
         if p_bid_str:
             p_banner.ParseFromString(p_bid_str)
             for i in xrange(len(p_banner.logic_rule.operation_rules)):
                 if p_banner.logic_rule.operation_rules[
                         i].operation_rule == rid:
                     del p_banner.logic_rule.operation_rules[i]
                     break
         cache.set("%s:RecBanner:%s" % (cid, p_bid),
                   p_banner.SerializeToString())
     ret = {}
     if rstr:
         ret["success"] = True
     else:
         ret["success"] = False
         ret["error_info"] = "can't delete operation rule."
     return pub.callback(json.dumps(ret), myuuid)
예제 #17
0
파일: wx_qr.py 프로젝트: emeitu/test
    def GET(self):
        ''' '/wx/qr' '''
        myuuid = uuid.uuid1()
        LOG("info", _myuuid=myuuid)
        args = web.input()
        if "method" in args:
            method = args["method"]
            if method == "getQrTicket":
                web.header('Content-Type', 'application/javascript')
                data = args["data"]
                ret = urllib2.urlopen(
                    "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=FoYOQEtQ-QHjnSv9tPDqpGOA49AFUZNqnQtPhhlRq_8i9XfxII3ofQGVtYpB6rjv",
                    data)
                retstr = ret.read()
                return pub.callback(retstr, myuuid)
            elif method == "getQr":
                gid = web.cookies().get("bfdid")
                print gid
                param_index = int(cache.get("G:weixin:paramindex"))
                web.header('Content-Type', 'image/png')
                if param_index == None:
                    param_index = 0
                    cache.set("G:weixin:paramindex", "0")
                else:
                    param_index = (int(param_index) + 1) % 100
                    cache.set("G:weixin:paramindex", str(param_index))
                access_token = cache.get("G:weixin:access_token")
                data = {
                    "expire_seconds": "1800",
                    "action_name": "QR_SCENE",
                    "action_info": {
                        "scene": {
                            "scene_id": str(param_index)
                        }
                    }
                }

                def getTicket(access_token):
                    ret = urllib2.urlopen(
                        "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token="
                        + access_token, json.dumps(data))
                    retstr = ret.read()
                    ticket = json.loads(retstr)["ticket"]
                    return ticket

                try:
                    ticket = getTicket(access_token)
                except:
                    appid = "wx68cc9091ef2be695"
                    secret = "c27b72cd1d51114cda5e816bbb95ab6d"
                    get_access_url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s' % (
                        appid, secret)
                    access_token_ret = urllib2.urlopen(get_access_url)
                    access_token = json.loads(
                        access_token_ret.read())["access_token"]
                    cache.set("G:weixin:access_token", access_token)
                    ticket = getTicket(access_token)

                qrurl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s" % ticket
                qrimg = urllib2.urlopen(qrurl)
                img = qrimg.read()
                cache.set("G:weixin:scene:%d" % param_index, gid)
                return img
            elif method == "getgid":
                web.header('Content-Type', 'application/javascript')
                open_id = args["open_id"]
                cid = args["cid"]
                if "scene_id" in args:
                    scene_id = args["scene_id"]
                    gid = cache.get("G:weixin:scene:%s" % scene_id)
                    cache.set("G:weixin:openid:%s:%s" % (cid, open_id), gid)
                    return pub.callback('"%s"' % gid, myuuid)
                else:
                    gid = cache.get("G:weixin:openid:%s:%s" % (cid, open_id))
                    return pub.callback('"%s"' % gid, myuuid)
            elif method == "getopenid":
                web.header('Content-Type', 'application/javascript')
                code = args['code']
                access_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx68cc9091ef2be695&secret=c27b72cd1d51114cda5e816bbb95ab6d&code=%s&grant_type=authorization_code' % code
                ret = urllib2.urlopen(access_url)
                return pub.callback(ret.read(), myuuid)

        else:
            web.header('Content-Type', 'application/javascript')
            return pub.callback(json.dumps(None), myuuid)
예제 #18
0
파일: bfdcache.py 프로젝트: emeitu/test
 def DELETE(self, n, b, k):
     myuuid = uuid.uuid1()
     LOG("info", _myuuid=myuuid)
     return pub.callback(cache.delete(k, n, b), myuuid)
예제 #19
0
 def GET(self, h, p, n, k):
     ''' /bfdrest/bfdredis/redis-server/port/db/key for get key;
     '''
     myuuid = uuid.uuid1()
     LOG("info", _myuuid=myuuid)
     return pub.callback(get(h, p, n, k), myuuid)
예제 #20
0
파일: bfdcache.py 프로젝트: emeitu/test
 def POST(self, n, b, k):
     myuuid = uuid.uuid1()
     LOG("info", _myuuid=myuuid)
     data = web.data()
     return pub.callback(cache.set(k, data, n, b), myuuid)