def post(self): items = self.request.POST.items() food_pool = [] for item in items: key, url = item[1].encode('utf-8').split('@', 1) print key food = Food.get_by_id(key) if food.image == url: continue else: food.image = url food.put()
def get(self, _id): food = Food.get_by_id(_id) result = { "name": food.name, "price": food.price, "wholesale_price": food.wholesale_price, "order": food.rank, "next": food.next_one, "prev": food.prev, "description": food.get_recommand(), "image": food.image } self.output(result)
def get(self, _id): result = Food.get_by_id(_id).infos result = [r.to_dict() for r in result] days = [r['date'] for r in result] day = datetime.datetime(2014,6,1) today = datetime.datetime.today() - datetime.timedelta(1) while day < today: day = day + datetime.timedelta(1) if day.date() in days: continue data = {} data['amount'] = 0 data['date'] = day.date() data['wholesale_price'] = 0 data['price'] = 0 result.append(data) result.sort(key=lambda x:x['date']) self.output(result)
def get(self, _id): food = Food.get_by_id(_id) composition = [{"name": "維生素B群 & C 菸鹼素", "amount": 5.2000, 'unit': "mg"}, {"name":"維生素E α-生育醇", "amount": 1.2400, "unit": "mg"}, {"name":"維生素E 維生素E總量", "amount": 3.0200, "unit": "mg"}, {"name":"礦物質 鈣", "amount": 33.0000, "unit": "mg"}] result = { "name": food.name, "price": food.price, "wholesale_price": food.wholesale_price, "order": food.rank, "next": food.next_one, "prev": food.prev, "description": food.get_recommand(), "image": food.image, "composition": composition, "type": "豬肉", } self.output(result)
def get(self, _id): result = Food.get_by_id(_id).infos result = [r.to_dict() for r in result] days = [r['date'] for r in result] day = datetime.datetime(2014, 6, 1) today = datetime.datetime.today() - datetime.timedelta(1) while day < today: day = day + datetime.timedelta(1) if day.date() in days: continue data = {} data['amount'] = 0 data['date'] = day.date() data['wholesale_price'] = 0 data['price'] = 0 result.append(data) result.sort(key=lambda x: x['date']) self.output(result)
def get(self, _id): food = Food.get_by_id(_id) datas = open('20_r').readlines() composition = [] pattern = re.sub("\(.*\)", "", _id) pattern = re.sub("-.*", "", pattern) for d in datas: if pattern in d: try: t1, t2, name, unit, value = d.split(' ') composition.append({"name": name, "amount":float(value.strip()), "unit":unit}) except Exception as e: print e composition = composition or [{"name": "碳水化合物", "unit": "mg", "amount": 1}] mapping = {"fish": '魚', 'meat': '肉', 'vegetable': '菜'} _type = mapping[food.type] result = { "name": food.name, "price": food.price, "wholesale_price": food.wholesale_price, "order": food.rank, "next": food.next_one, "prev": food.prev, "description": food.get_recommand(), "image": food.image, "composition": composition, "type": _type, } self.output(result)
def get(self, _id): food = Food.get_by_id(_id) composition = [{ "name": "維生素B群 & C 菸鹼素", "amount": 5.2000, 'unit': "mg" }, { "name": "維生素E α-生育醇", "amount": 1.2400, "unit": "mg" }, { "name": "維生素E 維生素E總量", "amount": 3.0200, "unit": "mg" }, { "name": "礦物質 鈣", "amount": 33.0000, "unit": "mg" }] result = { "name": food.name, "price": food.price, "wholesale_price": food.wholesale_price, "order": food.rank, "next": food.next_one, "prev": food.prev, "description": food.get_recommand(), "image": food.image, "composition": composition, "type": "豬肉", } self.output(result)
def get(self, _id): result = Food.get_by_id(_id).infos result = [r.to_dict() for r in result] self.output(result)