def add_item(item: Item): try: item.save() print(f"Added item {item.item_id}") return f"Added item: {item.json()}" except Exception as e: print("Error adding item", e) return None
def list_items_json(): query = Item.objects() json_string = query.to_json() dicts = json.loads(json_string) print(dicts) return json_string
def add_items(): req_data = request.get_json() item = Item(item_id=req_data['item_id'], name=req_data['name'], type=req_data['type'], price=req_data['price']) return itemService.add_item(item)
def delete_item(item_id): query = Item.objects(item_id=item_id) json_string = query.to_json() cnt = query.count() print(f"Count: {cnt}") query.delete() return json_string
def drop_loot(self): Quest.kills_until_treasure -= 1 r = rng.random() # lizardmen can drop the three treasures, in order if r < self.treasure_drop_rate and Quest.can_drop_treasure(): if not Quest.has_sword: self.world.add_item_at(Item(Tile.SWORD), self.x, self.y) Quest.reset_kills() elif not Quest.has_shield: self.world.add_item_at(Item(Tile.SHIELD), self.x, self.y) Quest.reset_kills() elif not Quest.has_crown: self.world.add_item_at(Item(Tile.CROWN), self.x, self.y) Quest.reset_kills() else: # no more treasures, just drop a potion self.world.add_item_at(Item(Tile.POTION), self.x, self.y) elif r < 0.4: self.world.add_item_at(Item(Tile.POTION), self.x, self.y)
def parse(): db_session.global_init("db/database.db") URL = 'https://www.e-katalog.ru/list/157/' HEADERS = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36 OPR/73.0.3856.438' } response = requests.get(URL, headers=HEADERS) soup = BeautifulSoup(response.content, 'html.parser') items = soup.findAll('table', class_='model-short-block') images = soup.findAll('div', class_='list-img h') comps = [] for i in range(24): item = items[i] about = item.find('div', class_='m-s-f2 no-mobile') # config = item.findAll('tr', class_='conf-tr') prev = [] #for el in config: # confs = el.findAll('td') # ab = [] # for c in confs: # text = c.get_text() # ab.append(text) # prev.append(ab) #string = '' #for el in prev: # string += ', '.join(el) + '/' mas = [] lies = about.findAll('div') for div in lies: text = div.get_text() mas.append(text) res = ', '.join(mas) #res += '|' + string comps.append({ 'title': item.find('span', class_='u').get_text(strip=True), 'price': item.find('div', class_='model-price-range').get_text(), 'about': res }) for i in range(24): comp = comps[i] img = images[i] item = Item() item.title = comp["title"] item.category = 'k13' price = comp["price"].split('.') item.price = price[0][5:14] #about = comp['about'].split('|,') item.about = comp['about'] #about = about[1].split('/,') #item.about_on_page = '\n'.join(about) item.image = 'images' + img.find('img')['src'] db_sess = db_session.create_session() db_sess.add(item) db_sess.commit()
def add_item(): # добавление товара if not current_user.moder: return redirect('/') form = ItemsForm() if form.validate_on_submit(): item = Item() item.name = form.name.data item.description = form.description.data item.price = form.price.data item.img = form.img.data item.quantity = form.quantity.data db_sess.add(item) db_sess.commit() return redirect('/') return render_template('items.html', title='Добавление Товара', form=form)
def create_enemies_and_items(self): num_enemies = 5 + self.player.level # more enemies as player levels up for i in range(num_enemies): # choose an enemy type if self.player.level == 1: t = rng.randrange(0, 2) # only slimes and bats at level 1 elif self.player.level < 5 and not Quest.has_shield: t = rng.randrange(0, 3) # lizardmen can spawn at low levels elif self.player.level < 6: t = rng.randrange(0, 4) # skeletons start to show up else: t = rng.randrange(0, 5) # lizard knights can spawn # spawn enemy of the chosen type if t == 0: slime = Slime(self.world, self, Tile.SLIME, 6, 2, 0, self.player) self.world.add_mob_at_random_empty_pos(slime) elif t == 1: bat = Bat(self.world, self, Tile.BAT, 10, 4, 0, self.player) self.world.add_mob_at_random_empty_pos(bat) elif t == 2: lizardman = Lizardman(self.world, self, Tile.LIZARD, 20, 6, 2, self.player) self.world.add_mob_at_random_empty_pos(lizardman) elif t == 3: lizardskelly = Lizardman(self.world, self, Tile.LIZARDBONES, 25, 8, 3, self.player) lizardskelly.treasure_drop_rate *= 2 lizardskelly.xp *= 2 self.world.add_mob_at_random_empty_pos(lizardskelly) elif t == 4: lizardknight = Lizardman(self.world, self, Tile.LIZARDKNIGHT, 30, 10, 4, self.player) lizardknight.vision += 1 lizardknight.treasure_drop_rate *= 3 lizardknight.xp *= 4 self.world.add_mob_at_random_empty_pos(lizardknight) num_items = num_enemies // 3 for i in range(num_items): self.world.add_item_at_random_empty_pos(Item(Tile.POTION))
def drop_loot(self): # Bats are harder so have higher chance to drop a potion if rng.random() < 0.4: self.world.add_item_at(Item(Tile.POTION), self.x, self.y)
def drop_loot(self): if rng.random() < 0.20: self.world.add_item_at(Item(Tile.POTION), self.x, self.y)
def list_item_json(item_id): query = Item.objects(item_id=item_id) json_string = query.to_json() return json_string
def list_items() -> List[Item]: query = Item.objects() items = list(query) return items