def sort(): vegetables = Food.query(Food.type=="vegetable").fetch(1000) vegetables.sort(key=lambda x:x.get_point()) vegetables.reverse() meats = Food.query(Food.type=="meat").fetch(1000) meats.sort(key=lambda x:x.get_point()) meats.reverse() fishs = Food.query(Food.type=="fish").fetch(1000) fishs.sort(key=lambda x:x.get_point()) fishs.reverse() c = 0 for vegetable in vegetables: print 'vegetable', c, vegetable.name vegetable.rank = c print vegetable.point if c: vegetable.prev = vegetables[c-1].name if c < len(vegetables) - 1: vegetable.next_one = vegetables[c+1].name c += 1 c=0 for meat in meats: print 'meat', c, meat.name print meat.point meat.rank = c if c: meat.prev = meats[c-1].name if c < len(meats) - 1: meat.next_one = meats[c+1].name c += 1 c=0 for fish in fishs: print 'fish', c, fish.name print fish.point fish.rank = c if c: fish.prev = fishs[c-1].name if c < len(fishs) - 1: fish.next_one = fishs[c+1].name c += 1 result = [] result.extend(vegetables) result.extend(fishs) result.extend(meats) ndb.put_multi(result)
def get(self): print(os.environ.get("FOOD_API_KEY")) start_template = jinja_current_dir.get_template( "templates/Recipes.html") user_foods = Food.query().order(Food.expiration_date).fetch() user_food_names = ",".join([food.food_name for food in user_foods]) query_params = { 'ingredients': user_food_names, 'apiKey': os.environ.get("FOOD_API_KEY"), } #not totally sure # recipe = Recipe.query().fetch() # self.response.write(start_template.render(recipe)) url = 'https://api.spoonacular.com/recipes/findByIngredients?%s' % ( urllib.urlencode(query_params)) # self.response.write(url) try: result = urlfetch.fetch(url) if result.status_code == 200: result_data = json.loads(result.content) else: result_data = [] self.response.status_int = result.status_code except urlfetch.Error: logging.exception('Caught exception fetching url') self.response.write(start_template.render({"recipes": result_data}))
def get(self, _type): size = int(self.request.get('size', 6)) page = int(self.request.get('page', 1)) foods = Food.query(Food.type==_type).fetch(1000) foods = sorted(foods, key= lambda x:x.rank)[size*page - size : size*page] result = [{"name":v.name, "price": v.price, "wholesale_price": v.wholesale_price, "image":v.image, "order": v.rank} for v in foods] self.output(result)
def sort(): vegetables = Food.query(Food.type=="vegetable").order(Food.point).fetch(1000) meats = Food.query(Food.type=="meat").order(Food.point).fetch(1000) fishs = Food.query(Food.type=="fish").order(Food.point).fetch(1000) c = 0 for vegetable in vegetables: print 'vegetable', c, vegetable.name vegetable.rank = c if c: vegetable.prev = vegetables[c-1].name if c < len(vegetables) - 1: vegetable.next_one = vegetables[c+1].name c += 1 c=0 for meat in meats: print 'meat', c, meat.name meat.rank = c if c: meat.prev = meats[c-1].name if c < len(meats) - 1: meat.next_one = meats[c+1].name c += 1 c=0 for fish in fishs: print 'fish', c, fish.name fish.rank = c if c: fish.prev = fishs[c-1].name if c < len(fishs) - 1: fish.next_one = fishs[c+1].name c += 1 result = [] result.extend(vegetables) result.extend(fishs) result.extend(meats) ndb.put_multi(result)
def get(self): foods = Food.query().fetch(1000) template = u"<label><img src='{1}'>{2}<input name='data' value='{0}@{1}'></label>" foods_template = "<br/>".join([template.format(food.name, food.image, food.type) for food in foods]) html = u''' <form method='post'> {} <input type='submit'> </form> '''.format(foods_template) self.response.write(html)
def get(self, _type): size = int(self.request.get('size', 6)) page = int(self.request.get('page', 1)) foods = Food.query(Food.type == _type).fetch(1000) foods = sorted(foods, key=lambda x: x.rank)[size * page - size:size * page] result = [{ "name": v.name, "price": v.price, "wholesale_price": v.wholesale_price, "image": v.image, "order": v.rank } for v in foods] self.output(result)
def set_image(): import google_search_image foods = Food.query().fetch(1000) for food in foods: try: print food.name, food.image assert not food.image, 'had image' key = u'{}'.format(food.name) print key img = google_search_image.search(key.encode('utf-8')).next() food.image = img.get('url') print food.name, food.image food.put() except Exception as e: print e
def set_image(): import google_search_image foods = Food.query().fetch(1000) import pdb;pdb.set_trace() for food in foods: try: print food.name, food.image assert not food.image, 'had image' key = u'{}'.format(food.name) print key img = google_search_image.search(key.encode('utf-8')).next() food.image = img.get('url') print food.name, food.image food.put() except Exception as e: print e
def get(self): foods = Food.query().fetch(1000) template = u"<label><img src='{1}'>{2}<input name='data' value='{0}@{1}'></label>" foods_template = "<br/>".join([ template.format(food.name, food.image, food.type) for food in foods ]) html = u''' <form method='post'> {} <input type='submit'> </form> '''.format(foods_template) self.response.write(html)
def get(self): food_list_template = jinja_current_dir.get_template( "templates/foodlist.html") fav_foods = Food.query().order(-Food.food_name).fetch(3) dict_for_template = {'top_fav_foods': fav_foods} self.response.write(food_list_template.render(dict_for_template))
def get(self): food_template = jinja_current_dir.get_template( "templates/Inventory.html") user_foods = Food.query().order(Food.expiration_date).fetch() dict_for_template = {'all_user_foods': user_foods} self.response.write(food_template.render(dict_for_template))
def get(self): food_list_template = jinja_current_dir.get_template("templates/foodlist.html") fav_foods = Food.query().order(-Food.food_name).fetch(3) dict_for_template = {'top_fav_foods': fav_foods} self.response.write(food_list_template.render(dict_for_template))