def single(): di="zheng" c = redis.Redis(host='127.0.0.1', port=6379, db=1) _name = { #"dou" : "小豆面馆", "meiming": "没名生煎", "jiahe" : "嘉禾一品", "yonghe" : "永和豆浆", "hehegu" : "和合谷", "jiye" : "吉野家", "kang" : "康师傅", "kfc" : "肯德基", "mac" : "麦当劳", "pizza" : "必胜客", "zheng" : "正一味", "zhen" : "真功夫", "xiao" : "三笑", #"hong" : "鸿毛饺子", } name = _name['%s'%di] print name url = "data/%s"%di print url json = {} json['name'] = name json['url'] = url json['cname'] = di print json json = helpers.json_encode(json) print c.lrem("dinner:list:all",0,json)
def single(path): #add single category #for example kfc.data dinner = path.split('.')[0] c = redis.Redis(host='127.0.0.1', port=6379, db=1) #c.delete("dinner:data:%s"%dinner) menu={} dishes=[] with open("%s"%path,"r") as f: data = f.readlines() for i in data: dish = {} li = i.split() name = li[0].decode('utf-8') price = str(int((float(li[1])*100))) dish['name'] = name dish['price'] = price print dish dishes.append(dish) #menu["category"] = u"水饺" menu["category"] = u"小食" menu["dishes"] = dishes menu = helpers.json_encode(menu) print menu c.lpush("dinner:data:%s"%dinner,menu)
def all(): c = redis.Redis(host='127.0.0.1', port=6379, db=1) c.delete("dinner:data:zheng") dinner = c.keys("dinner:data:*") c.delete("dinner:list:all") for di in dinner: json = {} print di di = di.split(":")[2] if di == "hong": continue _name = { #"dou" : "小豆面馆", "meiming": "没名生煎", "jiahe" : "嘉禾一品", "yonghe" : "永和豆浆", "hehegu" : "和合谷", "jiye" : "吉野家", "kang" : "康师傅", "kfc" : "肯德基", "mac" : "麦当劳", "pizza" : "必胜客", #"zheng" : "正一味", "zhen" : "真功夫", "xiao" : "三笑", #"hong" : "鸿毛饺子", } name = _name['%s'%di] print name url = "data/%s"%di print url json['name'] = name json['url'] = url json['cname'] = di print json json = helpers.json_encode(json) c.lpush("dinner:list:all",json) name = {} name['name'] = u"鸿毛饺子" name['url'] = "data/hong" name['cname'] = "hong" name = helpers.json_encode(name) c.lpush("dinner:list:all",name)
def get(self): c = redis.Redis(host='127.0.0.1', port=6379, db=1) li = c.lrange("dinner:list:all",0,-1) data = [] for i in li: i = helpers.json_decode(i) data.append(i) data = helpers.json_encode(data) self.set_header("Content-Type", "application/json") #self.set_header("Access-Control-Allow-Origin", "*") return self.finish(data)
def get(self,channel): c = redis.Redis(host='127.0.0.1', port=6379, db=1) li = c.lrange("dinner:data:%s"%channel,0,-1) #with open("kfc.list","r") as f: # li = f.read() #return self.finish(str(li)) data = [] for i in li: i = helpers.json_decode(i) data.append(i) data = helpers.json_encode(data) self.set_header("Content-Type", "application/json") return self.finish(data)
def post(self): id = self.get_argument('id') name = self.get_argument('name') if not name: c.delete("dinner:cname:%s"%id) else: c = redis.Redis(host='127.0.0.1', port=6379, db=1) c.set("dinner:cname:%s"%id,name) cname = c.get("dinner:cname:%s"%id) user = {} if cname: user['name'] = cname else: user['name'] = "" user['email'] = id user = helpers.json_encode(user) self.set_header("Content-Type", "application/json") return self.finish(user)
def post(self): id = self.get_argument('id') name = self.get_argument('name') if not name: c.delete("dinner:cname:%s" % id) else: c = redis.Redis(host='127.0.0.1', port=6379, db=1) c.set("dinner:cname:%s" % id, name) cname = c.get("dinner:cname:%s" % id) user = {} if cname: user['name'] = cname else: user['name'] = "" user['email'] = id user = helpers.json_encode(user) self.set_header("Content-Type", "application/json") return self.finish(user)
def get(self): if not self.current_user: raise tornado.web.HTTPError(403) return c = redis.Redis(host='127.0.0.1', port=6379, db=1) self.user = tornado.escape.json_decode(self.current_user) id = tornado.escape.xhtml_escape(self.user["email"]) str_time = time.strftime("%Y%m%d", time.localtime()) allorder = c.keys("dinner:%s:%s"%(str_time,id)) _order = c.lrange(allorder[0],0,-1) orders= [] for i in _order: _i = helpers.json_decode(i) orders.append(_i) all = {} all['id'] = id all['order'] = orders all = helpers.json_encode(all) return self.finish(all)
def get(self): if not self.current_user: raise tornado.web.HTTPError(403) return c = redis.Redis(host='127.0.0.1', port=6379, db=1) self.user = tornado.escape.json_decode(self.current_user) id = tornado.escape.xhtml_escape(self.user["email"]) str_time = time.strftime("%Y%m%d", time.localtime()) allorder = c.keys("dinner:%s:%s" % (str_time, id)) _order = c.lrange(allorder[0], 0, -1) orders = [] for i in _order: _i = helpers.json_decode(i) orders.append(_i) all = {} all['id'] = id all['order'] = orders all = helpers.json_encode(all) return self.finish(all)
def get(self): if not self.current_user: raise tornado.web.HTTPError(403) return c = redis.Redis(host='127.0.0.1', port=6379, db=1) self.user = tornado.escape.json_decode(self.current_user) email = tornado.escape.xhtml_escape(self.user["email"]) #email = tornado.escape.xhtml_escape(self.current_user["email"]) #name = tornado.escape.xhtml_escape(self.current_user["name"]) #name = tornado.escape.xhtml_escape(self.user["name"]) name = c.get("dinner:cname:%s" % email) user = {} if name: user['name'] = name else: user['name'] = "" user['email'] = email user = helpers.json_encode(user) self.set_header("Content-Type", "application/json") return self.finish(user)
def get(self): if not self.current_user: raise tornado.web.HTTPError(403) return c = redis.Redis(host='127.0.0.1', port=6379, db=1) self.user = tornado.escape.json_decode(self.current_user) email = tornado.escape.xhtml_escape(self.user["email"]) #email = tornado.escape.xhtml_escape(self.current_user["email"]) #name = tornado.escape.xhtml_escape(self.current_user["name"]) #name = tornado.escape.xhtml_escape(self.user["name"]) name = c.get("dinner:cname:%s"%email) user = {} if name: user['name'] = name else: user['name'] = "" user['email'] = email user = helpers.json_encode(user) self.set_header("Content-Type", "application/json") return self.finish(user)
def inputmenu(path): print path dinner = path.split('.')[0] print dinner #c = redis.Redis(host='127.0.0.1', port=6379, db=8) c = redis.Redis(host='10.0.25.74', port=6379, db=8) c.delete("dinner:data:%s" % dinner) with open("%s" % path, "r") as data: webdata = data.read() soup = BeautifulSoup(''.join(webdata)) all = soup all_list = all.findAll('ul', attrs={"class": "all_dishes_list"}) for ul in all_list: for lis in ul.contents: if not isinstance(lis, type(ul.contents[0])): cate = lis.find('h2').string menu = {} dishes = [] menu["category"] = cate print cate for li in lis.findAll('li'): name = li.find('span', {"class": "dishes_name_r"}).string price = li.find('span', {"class": "dishes_price"}).string price = int(float(price) * 100) dish = {} dish['name'] = name.strip("...").strip("+") dish['price'] = price print dish['name'] print dish['price'] dishes.append(dish) menu["dishes"] = dishes menu = helpers.json_encode(menu) # print menu if u"冰粥" in cate or u"早点" in cate or u"饮品" in cate or u"早餐" in cate or u"饮料" in cate or u"三人" in cate or u"10人" in cate or u"午餐" in cate or u"宵夜" in cate or u"双人" in cate or u"夜宵" in cate or u"匹萨" in cate: print cate print "--------------" continue else: c.lpush("dinner:data:%s" % dinner, menu) print "dinner:data:%s" % dinner print "++++++++++++++"
def inputmenu(path): print path dinner = path.split('.')[0] print dinner c = redis.Redis(host='127.0.0.1', port=6379, db=1) c.delete("dinner:data:%s" % dinner) with open("%s" % path, "r") as data: webdata = data.read() soup = BeautifulSoup(''.join(webdata)) all = soup all_list = all.findAll('ul', attrs={"class": "all_dishes_list"}) for ul in all_list: for lis in ul.contents: if type(lis) != type(ul.contents[0]): cate = lis.find('h2').string menu = {} dishes = [] menu["category"] = cate print cate for li in lis.findAll('li'): name = li.find('span', {"class": "dishes_name_r"}).string price = li.find('span', {"class": "dishes_price"}).string price = int(float(price) * 100) dish = {} dish['name'] = name.strip("...").strip("+") dish['price'] = price print dish['name'] print dish['price'] dishes.append(dish) menu["dishes"] = dishes menu = helpers.json_encode(menu) #print menu if u"早点" in cate or u"饮品" in cate or u"早餐" in cate or u"饮料" in cate or u"三人" in cate or u"10人" in cate or u"午餐" in cate or u"宵夜" in cate or u"双人" in cate or u"夜宵" in cate or u"匹萨" in cate: print cate print "--------------" continue else: c.lpush("dinner:data:%s" % dinner, menu) print "dinner:data:%s" % dinner print "++++++++++++++"
def hong(): c = redis.Redis(host='127.0.0.1', port=6379, db=1) dinner = "hong" c.delete("dinner:data:hong") menu={} dishes=[] with open("hong.data","r") as f: data = f.readlines() for i in data: dish = {} li = i.split() name = li[0].decode('utf-8') price = str(int((float(li[1])*100))) dish['name'] = name dish['price'] = price print dish dishes.append(dish) menu["category"] = u"水饺" menu["dishes"] = dishes menu = helpers.json_encode(menu) print menu c.lpush("dinner:data:%s"%dinner,menu)
def hong(): c = redis.Redis(host='127.0.0.1', port=6379, db=1) dinner = "hong" c.delete("dinner:data:hong") menu = {} dishes = [] with open("hong.data", "r") as f: data = f.readlines() for i in data: dish = {} li = i.split() name = li[0].decode('utf-8') price = str(int((float(li[1]) * 100))) dish['name'] = name dish['price'] = price print dish dishes.append(dish) menu["category"] = u"水饺" menu["dishes"] = dishes menu = helpers.json_encode(menu) print menu c.lpush("dinner:data:%s" % dinner, menu)
import helpers import redis channel = "kfc" c = redis.Redis(host='127.0.0.1', port=6379, db=1) li = c.lrange("dinner:data:%s"%channel,0,-1) data = [] for i in li: #i = eval(i) #i = helpers.json_decode(i) print type(i) i = helpers.json_decode(i) #i = helpers.json_encode(i) #print type(i) print i data.append(i) data = helpers.json_encode(data) #print type(data) print data print '========' #with open("%s.list"%channel) as f: # a = f.read() # print type(a) # print a ''' { "name": "肯德基", "content": [ { "category": "cate", "dishes": [ {
def main(): c = redis.Redis(host='127.0.0.1', port=6379, db=1) json='{"id": "*****@*****.**","order": [{"name":"麦乐鸡套餐","from":"mac","number": "1", "price": "1650"},{"name":"可乐","from":"kfc","number": "1","price": "800"}]}' json = helpers.json_decode(json) id = json['id'] #c.zrem("dinner:user:pop",id) #print c.zrange("dinner:user:pop",0,-1,withscores=True) ''' 统计活跃用户 ''' #c.zadd("dinner:user:pop",id,1) user_list = c.zrange("dinner:user:pop",0,-1) #print user_list if id in user_list: c.zincrby("dinner:user:pop",id,1) else: c.zadd("dinner:user:pop",id,1) str_time = time.strftime("%Y%m%d", time.localtime()) #print "dinner:%s:%s"%(str_time,json['id']) for i in json['order']: print "order:" print i rname = i['from'] name = i['name'] print rname ''' 统计流行的餐厅 ''' c.zadd("dinner:from:pop",rname,1) from_list = c.zrange("dinner:from:pop",0,-1) print "from_list:" print from_list #if rname.encode('utf8') in from_list: # c.zincrby("dinner:from:pop",rname,1) # print "ok" #else: # c.zadd("dinner:from:pop",rname,1) # print "not ok" ''' 统计流行的菜品 ''' c.zadd("dinner:dish:pop",rname,1) dish_list = c.zrange("dinner:dish:pop",0,-1) print "dish_list" print dish_list #if name.encode('utf8') in dish_list: # c.zincrby("dinner:dish:pop",name,1) # print "ok" #else: # c.zadd("dinner:dish:pop",name,1) # print "not ok" ''' 添加每个人每天的菜单 ''' li = helpers.json_encode(i) #print li c.lpush("dinner:%s:%s"%(str_time,json['id']),li) '''
def post(self): c = redis.Redis(host='127.0.0.1', port=6379, db=1) cx = sqlite3.connect("/home/work/diancan/data/dinner.db") cu = cx.cursor() json = self.get_argument('json') json = urllib2.unquote(json) json = helpers.json_decode(json) id = json['id'] if id.split("@")[1] != "wandoujia.com": raise tornado.web.HTTPError(403) return dead = int(time.strftime("%H%M",time.localtime())) if dead >= 1420: raise tornado.web.HTTPError(403) return ''' 统计活跃用户 ''' user_list = c.zrange("dinner:user:pop",0,-1) if id in user_list: c.zincrby("dinner:user:pop",id,1) else: c.zadd("dinner:user:pop",id,1) str_time = time.strftime("%Y%m%d", time.localtime()) bid = base64.encodestring(id.encode("utf-8")).strip() day = int(str_time) c.delete("dinner:%s:%s"%(str_time,id)) cu.execute('delete from orders where id = ? and day =?',(bid,day)) cx.commit() for i in json['order']: rname = i['from'] name = i['name'] bid = base64.encodestring(id.encode("utf-8")).strip() froms = base64.encodestring(rname.encode("utf-8")).strip() dish = base64.encodestring(name.encode("utf-8")).strip() number = int(i['number']) price = int(i['price']) day = int(str_time) ''' 统计流行的餐厅 ''' c.zadd("dinner:from:pop",rname,1) from_list = c.zrange("dinner:from:pop",0,-1) if rname.encode('utf-8') in from_list: c.zincrby("dinner:from:pop",rname,1) else: c.zadd("dinner:from:pop",rname,1) ''' 统计流行的菜品 ''' c.zadd("dinner:dish:pop",rname,1) dish_list = c.zrange("dinner:dish:pop",0,-1) #if name.encode('utf-8') in dish_list: if name.encode('utf-8') in dish_list: c.zincrby("dinner:dish:pop",name,1) else: c.zadd("dinner:dish:pop",name,1) ''' 添加每个人每天的菜单 ''' li = helpers.json_encode(i) c.lpush("dinner:%s:%s"%(str_time,json['id']),li) cu.execute('insert into orders (id,froms,dish,number,price,day) values(?,?,?,?,?,?)',(bid,froms,dish,number,price,day)) cx.commit() #self.set_header("Access-Control-Allow-Origin", "*") return self.finish("ok")
def see(): cx = sqlite3.connect("/home/work/diancan/data/dinner.db") cx.text_factory=str cu = cx.cursor() str_time = time.strftime("%Y%m%d", time.localtime()) #for i in cu.execute('select * from orders where day = "%s"'%(str_time)): # for j in i: # if type(j) == type("a"): # print base64.decodestring(j).decode('utf-8') # else: # print j all_froms = [] for i in cu.execute('select froms from orders where day = "%s"'%str_time): all_froms.append(i[0]) all_froms = list(set(all_froms)) all_list = [] for i in all_froms: #self.write("%s"%i) all = {} froms = i all['from'] = base64.decodestring(froms).decode('utf-8') print all['from'] #self.write(froms) #self.write(base64.decodestring(i[0]).decode('utf-8')) cu.execute('select sum(o.price*o.number) from orders o where o.froms = "%s" and o.day = "%s"'%(froms,str_time)) price = cu.fetchall()[0][0] all['price'] = price print all['price'] #cu.execute('select dish,number from orders where froms = "%s" and day = "%s" group by dish'%(froms,str_time)) ##self.write("%d"%price) #print cu.fetchall() orders = [] print "---------------" li = cu.execute('select dish,sum(number) from orders where froms = "%s" and day = "%s" group by dish'%(froms,str_time)) #li = cu.fetchall() print li #print len(li) print "&&&&&&&&&&&&&" for j in li: print j order = {} dish = j[0] order['dish'] = base64.decodestring(j[0]).decode('utf-8') print order['dish'] number = j[1] order['number'] = number print order['number'] people = [] sql = 'select id from orders where day = "%s" and froms = "%s" and dish = "%s"'%(str_time,froms,dish) print sql cu.execute(sql) print cu.fetchall() #for k in cu.execute('select id from orders where day = "%s" and froms = "%s" and dish = "%s"'%(str_time,froms,dish)): # people.append(base64.decodestring(k[0]).decode('utf-8')) #people = list(set(people)) #order['people'] = people #print order['people'] print "+++++++++++++" orders.append(order) print "====================" all['order'] = orders all_list.append(all) #cu.execute('select dish from orders o where froms = "%s"'%froms) #cu.execute('select dish from orders where froms = "%s" group by dish'%froms) #print cu.fetchall() all_list = helpers.json_encode(all_list)
import redis channel = "kfc" c = redis.Redis(host="127.0.0.1", port=6379, db=1) li = c.lrange("dinner:data:%s" % channel, 0, -1) data = [] for i in li: # i = eval(i) # i = helpers.json_decode(i) print type(i) i = helpers.json_decode(i) # i = helpers.json_encode(i) # print type(i) print i data.append(i) data = helpers.json_encode(data) # print type(data) print data print "========" # with open("%s.list"%channel) as f: # a = f.read() # print type(a) # print a """ { "name": "肯德基", "content": [ { "category": "cate", "dishes": [ {
def post(self): c = redis.Redis(host='127.0.0.1', port=6379, db=1) cx = sqlite3.connect("/home/work/diancan/data/dinner.db") cu = cx.cursor() json = self.get_argument('json') json = urllib2.unquote(json) json = helpers.json_decode(json) id = json['id'] if id.split("@")[1] != "wandoujia.com": raise tornado.web.HTTPError(403) return dead = int(time.strftime("%H%M", time.localtime())) if dead >= 1420: raise tornado.web.HTTPError(403) return ''' 统计活跃用户 ''' user_list = c.zrange("dinner:user:pop", 0, -1) if id in user_list: c.zincrby("dinner:user:pop", id, 1) else: c.zadd("dinner:user:pop", id, 1) str_time = time.strftime("%Y%m%d", time.localtime()) bid = base64.encodestring(id.encode("utf-8")).strip() day = int(str_time) c.delete("dinner:%s:%s" % (str_time, id)) cu.execute('delete from orders where id = ? and day =?', (bid, day)) cx.commit() for i in json['order']: rname = i['from'] name = i['name'] bid = base64.encodestring(id.encode("utf-8")).strip() froms = base64.encodestring(rname.encode("utf-8")).strip() dish = base64.encodestring(name.encode("utf-8")).strip() number = int(i['number']) price = int(i['price']) day = int(str_time) ''' 统计流行的餐厅 ''' c.zadd("dinner:from:pop", rname, 1) from_list = c.zrange("dinner:from:pop", 0, -1) if rname.encode('utf-8') in from_list: c.zincrby("dinner:from:pop", rname, 1) else: c.zadd("dinner:from:pop", rname, 1) ''' 统计流行的菜品 ''' c.zadd("dinner:dish:pop", rname, 1) dish_list = c.zrange("dinner:dish:pop", 0, -1) #if name.encode('utf-8') in dish_list: if name.encode('utf-8') in dish_list: c.zincrby("dinner:dish:pop", name, 1) else: c.zadd("dinner:dish:pop", name, 1) ''' 添加每个人每天的菜单 ''' li = helpers.json_encode(i) c.lpush("dinner:%s:%s" % (str_time, json['id']), li) cu.execute( 'insert into orders (id,froms,dish,number,price,day) values(?,?,?,?,?,?)', (bid, froms, dish, number, price, day)) cx.commit() #self.set_header("Access-Control-Allow-Origin", "*") return self.finish("ok")