def create_food(): food = Food(request.form['name'], request.form['description'], request.form['price'], request.form['image'], request.form['category_id']) food.new_food(food) return render_template('index.html', categories=Category.query.all(), foods=Food.query.all(), user=current_user, \ admin=admin_permission)
def new_recipe(self): name = input("Please enter the NAME of the food\n") preparation = input("Please enter the PREPARATION of the food\n") type_name = input("Please enter the TYPE of the food\n") if self.type_is_exists(type_name): typef = Types_Of_Food.find_one_type(ttype=type_name) type_id = typef['_id'] else: typef = Types_Of_Food(ttype=type_name) typef.save_type() typef = Types_Of_Food.find_one_type(ttype=type_name) type_id = typef['_id'] food = Food(name, preparation, type_id) food.save_food() while True: one_more = input("Do you want to add (another) ingredient? Y/N") if one_more.lower() == "y": # ingredient, quantity, unit, food_id, _id=None ing_name = input("Ingredient NAME?\n") ing_quant = input("Ingredient QUANTITY?\n") ing_unit = input("Ingredient UNIT?\n") ing_food_id = food.get_id() ingredient = Ingredients(ingredient=ing_name, quantity=ing_quant, unit=ing_unit, food_id=ing_food_id) Ingredients.save_ingredient(ingredient) else: break
def test_eating_food_is_done_correctly(self): self.python.set_head() self.python.set_body() size = len(self.python.get_body_coords()) self.game_world.set_cell(Cell(Food(), Vector2D(5, 6))) self.python.move('d') size_n = len(self.python.get_body_coords()) self.assertEqual(size_n - size, 1)
def get(self, *args, **kwargs): id = int(self.get_argument('id', [0])[0]) info = session.query(Food).filter_by(id=id).first() if info is None: info = Food() cat_list = session.query(FoodCat).all() current = 'index' self.render("food/set.html", info=info, cat_list=cat_list, current=current)
def home(): if request.method == "GET": return render_template('food_form.html') elif request.method == "POST": form = request.form # print(form) t = form['title'] l = form['link'] f = Food(title=t, link=l) f.save() return redirect("/food/" + str(f.id))
def add_food(): if request.method == "GET": return render_template("food_form.html") elif request.method == "POST": form = request.form # form la kieu dictionary # form hay user trong register la ten dict, request.form thi form la form o trong file html # print(form) t = form["title"] l = form["link"] # print(t, l) f = Food(title=t, link=l) f.save() return redirect("/food/" + str(f.id))
def addWordFood(): if request.method == "GET": return render_template("addWord.html") else: form = request.form add_word = Food( image=form["image"], word=form["word"], pronunciation=form["pronunciation"], mean=form["mean"], audio_link=form["audio_link"], ) add_word.save() return redirect(url_for('admin'))
def queryFood(): request_json = request.get_json() name = request_json['food'] if request.method == 'POST': tmp = Food(name, None, None, None, None) search = "%{}%".format(name) query = session.query(Food).filter(Food.food_name.like(search)) if query is None: return "False" else: query = query.all() dictlist = [] for food in query: dictlist.append(dict(food.asDict())) return json.dumps(dictlist) return "Not Okay"
def post_food(store_id): """ Creates a Food """ store = storage.get(Store, store_id) if not store: abort(404) if not request.get_json(): abort(400, description="Not a JSON") if 'name' not in request.get_json(): abort(400, description="Missing name") data = request.get_json() instance = Food(**data) instance.store_id = store.id instance.save() return make_response(jsonify(instance.to_dict()), 201)
def main(): game = GameWorld(20) cell1 = Cell(Food(), Vector2D(4, 4)) cell2 = Cell(Food(), Vector2D(6, 7)) cell3 = Cell(Food(), Vector2D(6, 8)) cell4 = Cell(Food(), Vector2D(2, 1)) cell5 = Cell(Food(), Vector2D(0, 17)) cell6 = Cell(Food(), Vector2D(13, 15)) cell7 = Cell(Food(), Vector2D(14, 2)) cell8 = Cell(Wall(), Vector2D(5, 5)) cell9 = Cell(Wall(), Vector2D(7, 6)) cell10 = Cell(Wall(), Vector2D(8, 9)) cell11 = Cell(Wall(), Vector2D(11, 15)) cell12 = Cell(Wall(), Vector2D(18, 12)) cell13 = Cell(Wall(), Vector2D(19, 1)) cell14 = Cell(BlackHole(), Vector2D(2, 2)) game.add_content([cell1, cell2, cell3, cell4, cell5, cell6, cell7, cell8, cell9, cell10, cell11, cell12, cell13, cell14]) p = Python(game, (5, 2), 5, Python.DOWN) p.set_head() p.set_body() game.print_world() direction = getch.getch() with start_log('game_start.txt', 'a') as s: pass while direction: os.system('clear') p.move(direction) with move_log('move_log.txt', 'a', p.direction_by_ascii_code(direction)) as f: pass flag = p.is_dead() try: if not flag: game.print_world() direction = getch.getch() else: raise DeathError except DeathError: print("GAME OVER") break if game.no_food_board(): print("GAME WON!") break with end_log('game_end.txt', 'a') as e: pass
def get(self, *args, **kwargs): resp_data = {} id = int(self.get_argument('id', 0)) info = Food(id=0, name='', cat_id='', price='', main_image='', summary='', stock='', tags='') if id != 0: info = session.query(Food).filter_by(id=id).first() if not info: self.redirect('/food/index') cat_list = session.query(FoodCat).all() resp_data['info'] = info resp_data['cat_list'] = cat_list resp_data['current'] = 'index' self.render("food/set.html", **resp_data)
def post(self, request): # 创建食品 owner = request.u store = owner.store name = request.json.get("name") description = request.json.get("description") price = float(request.json.get("price")) stock = int(request.json.get("stock")) image_ids = request.json.get("image_ids") if not all([store, name, description, price, stock]): return JsonErrorResponse("store, name, description, price, stock are needed", 400) new_food = Food( name=name, description=description, price=price, stock=stock, image_ids=image_ids, store=store ) try: new_food.save() except Exception, e: print e return JsonErrorResponse("Fail:" + e.message)
def test_no_food_board_on_set_food_cell(self): self.game_world.set_cell(Cell(Food(), Vector2D(3, 4))) self.assertFalse(self.game_world.no_food_board())
#!/usr/bin/python3 from models.base import BaseModel from models.store import Store from models.food import Food from models.drink import Drink from models.order import Order from models import storage from models.confirmation import Confirmation my_store = Store(name="JV") my_store.save() my_food = Food(price=4000, store_id=my_store.id, name="Tinto") my_food.save() my_drink = Drink(price=5000, store_id=my_store.id, name="Cafe") my_drink.save() my_order = Order(order_number=1, drink_id=my_drink.id, store_id=my_store.id, user_name="Juan") my_order.save() all_order = storage.all(Order) my_confirmation = Confirmation(store_id=my_store.id, order_id=my_order.id, order_number=3, status="In Progress") my_confirmation.save()
import mlab from models.food import Food mlab.connect() # 1. Create # B1: Create a food f = Food(title="Banh sai", link="<<link sai>>") # B2: Save it # f.save() # 2. Read # B1: Get cursor f_objects = Food.objects() # Lazy loading # Same as list # B2: Process cursor # f_first = f_objects[0] # Thực sự truyền dữ liệu # print(f_first.title) # print(f_first.link) # print(len(f_objects)) # print(f_objects.count()) # Bảo database đếm # for f in f_objects: # print(f.title) # print(f.link) # print("----------------") # f = f_objects[4] # f.update(set__title= "Banh rat rat ngon", set__link= "Link ngon") # #op__prop: hành động __ cần thay đổi # # chỉ xảy ra trong database
def generate_food(self): self.food = [Food() for _ in range(settings.FOOD_COUNT)]
import mlab from models.food import Food import pyexcel import pandas as pd from pandas import ExcelWriter from pandas import ExcelFile mlab.connect() df = pd.read_excel('Crawdata.xlsx', sheet_name='pyexcel_sheet1') for i in df.index: food = Food(title=df['title'][i], img=df['img'][i], nguyenlieu=df['nguyenlieu'][i].strip("\n").replace(" ",""), cachlam=df['cachlam'][i]) # food.save() print("Completed")
from models.food import Food food = Food('pasta alla carbonara', 'primo piatto', 'pasta', 'uova e pancetta') print(food)
def setUp(self): self.cell = Cell(Food())
def post(cls): ##################REFACTOR############## data = { 'type': request.args.get('type'), 'sr': request.args.get('sr'), 'ndbno': int(request.args.get('ndbno')), 'name': request.args.get('name'), 'sd': request.args.get('sd'), 'fg': request.args.get('fg'), 'ds': request.args.get('ds'), 'food_list_id': int(request.args.get('food_list_id')) } schema = { 'type': { 'type': 'string' }, 'sr': { 'type': 'string' }, 'quantity': { 'type': 'integer' }, 'ndbno': { 'required': True, 'type': 'integer' }, 'name': { 'required': True, 'type': 'string' }, 'sd': { 'required': True, 'type': 'string' }, 'fg': { 'required': True, 'type': 'string' }, 'ds': { 'required': True, 'type': 'string' }, 'food_list_id': { 'required': True, 'type': 'integer' } } v = Validator(schema) if not v(data): return { 'message': 'Something wrong with your Validators: {}'.format(v.errors) }, 400 try: food = Food(**data).save_to_db() return 'Food has been saved' except Exception as e: return 'Food could not be saved, {}'.format(e)
def create(): logged_in_user_id = request.form.get('user_id') food_name = request.form.get('food_name') criterion_z1 = int(request.form.get('criterion_z1')) criterion_z2 = int(request.form.get('criterion_z2')) criterion_z3 = int(request.form.get('criterion_z3')) criterion_z4 = int(request.form.get('criterion_z4')) criterion_z5 = int(request.form.get('criterion_z5')) food_picture = request.files['food_picture'] latitude = float(request.form.get('latitude')) longitude = float(request.form.get('longitude')) price = float(request.form.get('price')) # logged_in_user_id = request.json.get("user_id") # food_name = request.json.get('food_name') # criterion_z1 = request.json.get('criterion_z1') # criterion_z2 = request.json.get('criterion_z2') # criterion_z3 = request.json.get('criterion_z3') # criterion_z4 = request.json.get('criterion_z4') # criterion_z5 = request.json.get('criterion_z5') # food_picture = request.json.get('food_picture') # latitude = request.json.get('latitude') # longitude = request.json.get('longitude') # price = request.json.get('price') # tag_list = request.json.get('tag_list') food_already_exist = Food.select().where( Food.name == food_name, Food.latitude > latitude - 0.0002, Food.latitude < latitude + 0.0002, Food.longitude > longitude - 0.0002, Food.longitude < longitude + 0.0002) # print(food_already_exist, "FOOD ALREADY EXIST OBJECT") food_already_exist_id_arr = [ food_already_exist_element.id for food_already_exist_element in food_already_exist ] # print(food_already_exist_id_arr, "FOOD ALREADY EXIST ARRAY") # print(food_already_exist_id_arr[0], "FIRST INDEX FOOD ALREADY EXIST") if food_already_exist: review_already_exist = Review.get_or_none( user_id=logged_in_user_id, food_id=food_already_exist_id_arr[0]) # print(review_already_exist, "REVIEW ALREADY EXIST") if review_already_exist: print("HELLO WORLD I WENT IN ") return jsonify({ "status": "failed", "message": "You have already submitted a review for this dish in this location" }), 400 else: print("I AM CREATING A REVIEW INSTANCE") new_review_instance = Review(user_id=logged_in_user_id, food_picture=food_picture, criterion_z1=criterion_z1, criterion_z2=criterion_z2, criterion_z3=criterion_z3, criterion_z4=criterion_z4, criterion_z5=criterion_z5, food_id=food_already_exist_id_arr[0]) if new_review_instance.save(): file = request.files['food_picture'] if file and allowed_file(file.filename): file.filename = secure_filename(file.filename) output = upload_file_to_s3(file, S3_BUCKET_NAME) food_picture = str(output) new_review_instance = Review( user_id=logged_in_user_id, food_picture=food_picture, criterion_z1=criterion_z1, criterion_z2=criterion_z2, criterion_z3=criterion_z3, criterion_z4=criterion_z4, criterion_z5=criterion_z5, food_id=food_already_exist_id_arr[0]) if new_review_instance.save(): # Creation of tag # for tag_element in tag_list: # tag_already_exist = Tag.get_or_none(name = tag_element) # if tag_already_exist: # new_tag_review_instance = TagReview(review_id = new_review_instance.id, tag_id = tag_already_exist.id) # new_tag_review_instance.save() # else: # new_tag_instance = Tag(name = tag_element) # new_tag_instance.save() # new_tag_instance_id = Tag.get_or_none(name = tag_element).id # new_tag_review_instance = TagReview(review_id = new_review_instance.id, tag_id = new_tag_instance_id) # new_tag_review_instance.save() # if food image upload success return jsonify({ "logged_in_user_id": logged_in_user_id, "food_picture": food_picture, "criterion_z1": criterion_z1, "criterion_z2": criterion_z2, "criterion_z3": criterion_z3, "criterion_z4": criterion_z4, "criterion_z5": criterion_z5, "food_id": food_already_exist.id, "price": price, "latitude": latitude, "longitude": longitude # "tag_list": tag_list }), 200 else: # if jsonify error return jsonify({"err": "Something went wrong"}), 400 else: return jsonify({"err": "Something went wrong"}), 400 # if image fail to upload else: new_food_instance = Food(name=food_name, longitude=longitude, latitude=latitude, price=price) if new_food_instance.save(): print(food_picture) # print(food_picture.files) file = request.files['food_picture'] print(file.filename) if file and allowed_file(file.filename): file.filename = secure_filename(file.filename) output = upload_file_to_s3(file, S3_BUCKET_NAME) food_picture = str(output) # print(food_name,"NAME OF FOOD") # print(latitude, "LATTITUDE") # print(longitude, "LONGITUDE") # print(type(latitude), "LATITUDE TYPE OF") # print(type(longitude), "LONTITUDE TYPE OF") latitude = str(latitude) longitude = str(longitude) # print(latitude, "LATTITUDE 2") # print(longitude, "LONGITUDE 2") # print(type(latitude), "LATITUDE TYPE OF 2") # print(type(longitude), "LONTITUDE TYPE OF 2") new_food_instance = Food.get_or_none(name=food_name, longitude=longitude, latitude=latitude) # print(new_food_instance, "REVIEW INSTANCE") # print(new_food_instance.id, "REVIEW INSTANCE ID") new_review_instance = Review(user_id=logged_in_user_id, food_picture=food_picture, criterion_z1=criterion_z1, criterion_z2=criterion_z2, criterion_z3=criterion_z3, criterion_z4=criterion_z4, criterion_z5=criterion_z5, food_id=new_food_instance.id) if new_review_instance.save(): # Creation of tag # for tag_element in tag_list: # tag_already_exist = Tag.get_or_none(name = tag_element) # if tag_already_exist: # new_tag_review_instance = TagReview(review_id = new_review_instance.id, tag_id = tag_already_exist.id) # new_tag_review_instance.save() # else: # new_tag_instance = Tag(name = tag_element) # new_tag_instance.save() # new_tag_instance_id = Tag.get_or_none(name = tag_element).id # new_tag_review_instance = TagReview(review_id = new_review_instance.id, tag_id = new_tag_instance_id) # new_tag_review_instance.save() # if food image upload success return jsonify({ "logged_in_user_id": logged_in_user_id, "food_picture": food_picture, "criterion_z1": criterion_z1, "criterion_z2": criterion_z2, "criterion_z3": criterion_z3, "criterion_z4": criterion_z4, "criterion_z5": criterion_z5, "food_id": new_food_instance.id, "price": price, "latitude": float(latitude), "longitude": float(longitude) # "tag_list": tag_list }), 200 else: # if jsonify error return jsonify({"err": "Something went wrong"}), 400 else: return jsonify({"err": "Something went wrong"}), 400 # if image fail to upload else: return jsonify({"err": "Something went wrong"}), 400
def post(self, *args, **kwargs): resp = {'code': 200, 'msg': '操作成功~~', 'data': {}} id = int(self.get_argument('id', 0)) cat_id = int(self.get_argument('cat_id', 0)) name = self.get_argument('name', '') price = self.get_argument('price', '') main_image = self.get_argument('main_image', '') summary = self.get_argument('summary', '') stock = int(self.get_argument('stock', '')) tags = self.get_argument('tags', '') if cat_id < 1: resp['code'] = -1 resp['msg'] = "请选择分类~~" self.finish(resp) return if name is None or len(name) < 1: resp['code'] = -1 resp['msg'] = "请输入符合规范的名称~~" self.finish(resp) return if not price or len(price) < 1: resp['code'] = -1 resp['msg'] = "请输入符合规范的售卖价格~~" self.finish(resp) return price = Decimal(price).quantize(Decimal('0.00')) if price <= 0: resp['code'] = -1 resp['msg'] = "请输入符合规范的售卖价格~~" self.finish(resp) return if main_image is None or len(main_image) < 3: resp['code'] = -1 resp['msg'] = "请上传封面图~~" self.finish(resp) return if summary is None or len(summary) < 3: resp['code'] = -1 resp['msg'] = "请输入图书描述,并不能少于10个字符~~" self.finish(resp) return if stock < 1: resp['code'] = -1 resp['msg'] = "请输入符合规范的库存量~~" self.finish(resp) return if tags is None or len(tags) < 1: resp['code'] = -1 resp['msg'] = "请输入标签,便于搜索~~" self.finish(resp) return food_info = session.query(Food).filter_by(id=id).first() before_stock = 0 if food_info: model_food = food_info before_stock = model_food.stock else: model_food = Food() model_food.status = 1 model_food.created_time = getCurrentDate() model_food.cat_id = cat_id model_food.name = name model_food.price = price model_food.main_image = main_image model_food.summary = summary model_food.stock = stock model_food.tags = tags model_food.updated_time = getCurrentDate() session.add(model_food) session.commit() FoodService.setStockChangeLog(model_food.id, int(stock) - int(before_stock), "后台修改") self.finish(resp)
from models.food import Food from models.category import Category Base = declarative_base() engine = create_engine('sqlite:///database') Base.metadata.create_all(engine) Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) db = DBSession() new_food = Food(name='Pizza Paperos', description='My food', price=29, image='asdasd', category_id=2) new_category = Category(name='Bif Burger') new_category1 = Category(name='Sup') new_category2 = Category(name='Pizaa') #db.add(new_category) #db.add(new_category1) #db.add(new_category2) #db.commit() #.filter_by(category_id=1) Base.metadata.drop_all(engine) foods = db.query(Food).filter_by(category_id=2).all()
snake_dir = 'east' # Game variables gameOver = False gameStarted = False score = 0 highscore = 0 pygame.init() pygame.display.set_caption("Snake Game") window = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) grid = Grid(window, SCREEN_WIDTH, SCREEN_HEIGHT, SQUARE_SIZE) snake = Snake(snake_pos_x, snake_pos_y, snake_dir, SQUARE_SIZE) food = Food(15, 15, SCREEN_WIDTH / SQUARE_SIZE, SCREEN_HEIGHT / SQUARE_SIZE, SQUARE_SIZE) menu = Menu(window, SCREEN_WIDTH, SCREEN_HEIGHT) clock = pygame.time.Clock() while True: pygame.time.delay(40) clock.tick(10) if gameStarted == False: menu.draw(score, highscore) if gameOver == False and gameStarted: grid.draw(snake, food) snake.move()
"image": "../static/images/food16.jpg", "word": "Sandwich", "pronunciation": "/ˈsænwɪdʒ/", "mean": "Bánh kẹp", "audio_link": "https://www.oxfordlearnersdictionaries.com/media/english/us_pron/s/san/sandw/sandwich__us_2.mp3", }, ] for i in list_food: db = Food(image=i["image"], word=i["word"], pronunciation=i["pronunciation"], mean=i["mean"], audio_link=i["audio_link"]) # db.save() list_actions = [ { "image": "../static/images/act1.jpg", "word": "Adjust", "pronunciation": "/əˈdʒʌst/", "mean": "Điều chỉnh", "audio_link": "https://www.oxfordlearnersdictionaries.com/media/english/us_pron/a/adj/adjus/adjust__us_1.mp3", "example": "It's difficult to adjust to the new climate.", }, { "image": "../static/images/act2.jpg",