def generate_item(self, item_name): item_sales = self.get_sales_info_json(item_name) # no item sales on bitskins #todo return None if len(item_sales) == 0: return Item(item_name, 0) name = item_sales[0]["market_hash_name"] price = self.calculate_price(item_sales) return Item(name, round(price, 2))
def load_items(file): # delete existing items table rows Item.query.delete() for row in open(file): name, description = row.rstrip().split("|") item = Item(name=name, description=description) db.session.add(item) db.session.commit() print("Items===========ADDED")
def generate_items(self, item_soups): items = [] for soup in item_soups: list_items = soup.find_all("li") for list_item in list_items: # todo optimize selecting item name and price item_name = str(list_item.find_all("a")[0].get("title")) item_price_string = str(list_item.find("strong", {"class": "f_Strong"})) price_array = re.findall(r'\d+', item_price_string) if len(price_array) == 1: price_array.append("0") item_price = float(price_array[0] + "." + price_array[1]) items.append(Item(item_name, item_price)) return items
def test_take_command_item_with_keyword(self): user_input = ["take", "keyword"] item = Item.Item("test 2", ["keyword"], "Short desc 2", "Long desc 2", True, True) room = Room.Room("Test Room", "This is a test room for testing.", {}, [item], []) player = Player.Player(room, [Test_Objects.TEST_ITEM_IN_INVENTORY]) self.assertTrue(item in room.items) self.assertTrue(item not in player.inventory) actual = Commands.parse_take_command(user_input, player) self.assertTrue(item not in room.items) self.assertTrue(item in player.inventory) self.assertEqual("You take the test 2.", actual)
def generate_items(self, soup): items = [] list_items = soup.findAll("div", {"class": "item"}) for list_item in list_items: # todo optimize selecting item name and price item_name = str( list_item.find("img", { "class": "itemimg" }).get("alt")) price_and_discount_string = list_item.find("div", { "class": "price" }).text price_and_discount = price_and_discount_string.split("-") item_price = float(price_and_discount[0].replace("$", "").replace( ",", "").replace("?%", "")) items.append(Item(item_name, item_price)) return items
from game import Item, Container # Quest items DOG_FIGURINE = Item.Item( "dog figurine", ["dog", "figurine", "figure"], "This is a dog figurine.", "This is a small garden ornament in the shape of a dog. Nan's probably " "looking for this.", False, False) # Gideon has this. PIG_FIGURINE = Item.Item( "pig figurine", ["pig", "figurine", "figure"], "This is a pig figurine.", "This is a small garden ornament in the shape of a pig. Nan's probably " "looking for this.", False, True) # Azuri has this. CAT_FIGURINE = Item.Item( "cat figurine", ["cat", "figurine", "figure"], "This is a cat figurine.", "This is a small garden ornament in the shape of a cat. Nan's probably " "looking for this.", False, True) # In cat toy box. MOUSE_FIGURINE = Item.Item( "mouse figurine", ["mouse", "figurine", "figure"], "This is a mouse figurine.", "This is a small garden ornament in the shape of a mouse. Nan's probably " "looking for this.", True, True) # In bathroom. BEAR_FIGURINE = Item.Item( "bear figurine", ["bear", "figurine", "figure"], "This is a bear figurine.", "This is a small garden ornament in the shape of a bear. Nan's probably " "looking for this.", True, True) # Molly has this in the shed. # Flavor items BALL = Item.Item("ball", ["ball"], "This is a ball.", "This is a small brightly-colored ball. The cats love it.", False, False)
from game import Room, Item knife = Item('knife', 'A pointy looking thing. Might be good att stabbing things', 3, 2) sword = Item('sword', 'A big bad sword', 4, 4) world = {} world['entrance'] = Room( 'entrance', 'You stand in the entrance of a big house. To the north is a door', ['n'], {'n': 'ballroom'}, [knife]) world['ballroom'] = Room( 'ballroom', 'You walk in to a big ballroom. In the middle of the room in the floor lies a blänkande svärd! \nThere is a door to the west, east and sout', ['s'], {'s': 'entrance'}, [sword, knife])
from game import Item, Person, Player, Room, Container from game.people import Gideon # Test Objects # Items TEST_ITEM_IN_INVENTORY = Item.Item("test", ["keyword"], "Short desc", "Long desc", True, True) TEST_ITEM_ON_GROUND = Item.Item("test 2", ["keyword"], "Short desc 2", "Long desc 2", True, True) TEST_ITEM_NOT_PRESENT = Item.Item("test not present", ["keyword"], "Short desc not present", "Long desc not present", True, True) TEST_ITEM_NO_GET = Item.Item("test ungettable", ["keyword"], "Short desc ungettable", "Long desc ungettable", True, False) TEST_ITEM_NO_VIS = Item.Item("test invisible", ["keyword"], "Short desc invisible", "Long desc invisible", False, True) # Containers TEST_EMPTY_CONTAINER = Container.Container("test", ["keyword"], "Short desc", "Long desc", True, False, []) TEST_CONTAINER_WITH_ITEM = Container.Container("test", ["keyword"], "Short desc", "Long desc", True, False, [TEST_ITEM_ON_GROUND]) TEST_CONTAINER_WITH_INVISIBLE_ITEM = Container.Container( "test", ["keyword"], "Short desc", "Long desc", True, False, [TEST_ITEM_NO_VIS]) # People
def test_item_say(self): item = Item("rock") self.assertEqual(item.say(), "...")