def test_update_quality__quality_lower_by_one(): ashbringer = Item('Ashbringer', 25, 40) warglaives = Item('Warglaives', 35, 40) gilded_rose = GildedRose([ashbringer, warglaives]) gilded_rose.update_quality() assert ashbringer.quality == 39 assert warglaives.quality == 39
def test_update_quality__sell_in_lower_by_one(): ashbringer = Item('Ashbringer', 25, 40) warglaives = Item('Warglaives', 35, 40) gilded_rose = GildedRose([ashbringer, warglaives]) gilded_rose.update_quality() assert gilded_rose.items[0].sell_in == 24 assert ashbringer.sell_in == 24 assert warglaives.sell_in == 34
def __parse_items(raw_character): jewels = raw_character[CharacterKeys.JEWELS.value] raw_items = raw_character[CharacterKeys.ITEMS.value] item_list = [] jewel_list = [] for item in raw_items: item_list.append(Item.from_dict(item)) # find socketed jewels for jewel in jewels: jewel_list.append(Item.from_dict(jewel)) return item_list, jewel_list
async def _buy_item(self, ctx, item_id: int = 0, count: int = 0): """Buy an item from the store.""" item_object = Item(item_id) cost = item_object.get_price() * count player = Player(ctx.message.author.id) balance = player.get_balance() wallet = balance['wallet'] if cost > wallet: return await ctx.send("Not enough cash. Need: " + str(cost)) else: player.add_balance('wallet', -cost) player.add_to_inventory(item_id, count) return await ctx.send("Successfully purchased.")
def test_update_quality__quality_lower_by_2x_after_sell_in(): ashbringer = Item('Ashbringer', -1, 40) gilded_rose = GildedRose([ashbringer]) gilded_rose.update_quality() assert ashbringer.quality == 38
def get_specials(name): items = [] items_data = Datastore.find('item_specials', {"store": name}) for data in items_data: item = Item(**data) items.append(item) return items
def do_post_create_item(self): post_data = get_raw_post_data(self) item_dict = parse_json(post_data) # Pull out all of the fields we need identifier = get_value(item_dict, 'identifier') price = parse_float(get_value(item_dict, 'price', 0)) billing_method = get_value(item_dict, 'billing_method', '') special = get_value(item_dict, 'special') # Ensure that all necessary data is present msg = '' if identifier is None or identifier == '': msg += 'Must provide identifier. ' if price is None or price <= 0: msg += 'Must provide price and must be positive. ' if msg != '': set_response(self, 400, msg, 'text/text') else: # Check to see if the provided special is valid if special is not None: msg = validate_special(special, billing_method) if msg != '': set_response(self, 400, msg, 'text/text') else: # Create and store the item and tell the user everything is fine item = Item(identifier, price, billing_method, special) datastore.set('itemdetails:' + item.identifier, item) set_response(self, 200, '')
def add(self, name, location_id, set_id=None, items=None): if items is None: items = [] self.c.execute( '''SELECT id, name, location_id FROM wars_stores WHERE name=?''', (name, )) fetch = self.c.fetchone() if fetch: raise Exception('existing name') else: self.c.execute('''SELECT MAX(id) FROM wars_stores''') fetch = self.c.fetchone() max_id = fetch[0] if max_id is None: max_id = 0 if set_id is None: set_id = max_id + 1 settings = dict() prices = dict() for item in self.items.list(): prices[item['id']] = Item(item['id']).get_price() prices['date'] = time() settings['prices'] = prices settings['available_items'] = items settings_json = json.dumps(settings) self.c.execute('''INSERT INTO wars_stores Values (?, ?, ?, ?)''', (set_id, name, location_id, settings_json)) self.conn.commit() return
def get(self, name): connect = sqlite3.connect('data.db') cursor = connect.cursor() query = "SELECT * FROM items where name=?" result = cursor.execute(query, (name, )) item = result.fetchone() return Item(*item).json()
def test_update_quality__quality_not_less_than_0(): ashbringer = Item('Ashbringer', 10, 0) negatives = [-5, -4, -3, -2, -1] gilded_rose = GildedRose([ashbringer]) gilded_rose.update_quality() assert ashbringer.quality != -1 assert ashbringer.quality not in negatives
def get(self): connect = sqlite3.connect('data.db') cursor = connect.cursor() query = "SELECT * FROM items" result = cursor.execute(query) items = result.fetchall() Items = [] for item in items: Items.append(Item(*item).json()) return Items
async def _add_item_to_inventory(self, ctx, item_id: int = 0, count: int = 0): """Add any item to inventory""" player = Player(ctx.message.author.id) player.add_to_inventory(item_id, count) item_object = Item(item_id) await ctx.send( str(count) + ' of ' + item_object.name + ' added to inventory')
def get_items(self, webdriver): content = webdriver.get_page() soup = BeautifulSoup(content, "html.parser") elements = soup.find_all("div", {"class": "shelfProductTile-content"}) items = [] for element in elements: try: # Get Name name = element.find("a", { "class": "shelfProductTile-descriptionLink" }).text.strip() #Get Url urlPath = element.find( "a", {"class": "shelfProductTile-descriptionLink"})['href'] url = "{}{}".format(self.domain, urlPath) #Get Price dollars = element.find("span", {"class": "price-dollars"}) dollars = dollars.text.strip() if dollars is not None else None cents = element.find("span", {"class": "price-cents"}) cents = cents.text.strip() if cents is not None else None price = float( "{}.{}".format(dollars, cents) ) if dollars is not None and cents is not None else None #Get Image image_url = element.find( "img", {"class": "shelfProductTile-image"})['src'].strip() #Get Id match = re.search("\/\d*(?=.jpg$)", image_url) matchGroup = match.group() if match is not None else None id = matchGroup[1:] if matchGroup is not None else None if id is not None: item = Item(self.store, name, price, url, image_url, id) item.save_to_mongo() else: print("Invalid ID: {}".format(image_url)) except Exception as e: print(e) print("Error - getting item: {}".format(element))
async def _list_items(self, ctx): await ctx.trigger_typing() items = self.items.list() embed = discord.Embed(title='Available Items', description='Some text') for item in items: item_object = Item(item['id']) if item['price_min'] != item['price_max']: market_price = item_object.get_price() else: market_price = item['price_min'] embed.add_field( name=item['name'], value='ID: ' + str(item['id']) + '\nEmoji: ' + item['emoji'] + '\nDescription :' + item['description'] + '\nMin Price: ' + str(item['price_min']) + '\nMax Price: ' + str(item['price_max']) + '\nMarket Price: ' + str(market_price) ) await ctx.send(embed=embed)
def test_update_quality__quality_not_more_than_50(): ashbringer = Item('Ashbringer', 10, 50) aged_brie = AgedBrie('Aged Brie', 10, 50) backstage_passes = Passes('Backstage passes to a TAFKAL80ETC concert', 3, 50) fifties = [51, 52, 53, 54, 55] gilded_rose = GildedRose([ashbringer, aged_brie, backstage_passes]) gilded_rose.update_quality() assert ashbringer.quality == 49 assert aged_brie.quality != 51 assert aged_brie.quality not in fifties assert backstage_passes.quality != 53 assert backstage_passes.quality not in fifties
def new_alert(): if request.method == 'POST': alert_name = request.form['name'] item_url = request.form['item_url'] price_limit = float(request.form['price_limit']) store = Store.find_by_url(item_url) item = Item(item_url, store.tag_name, store.query) item.load_price() item.save_to_mongo() Alert(alert_name, item._id, price_limit, session['email']).save_to_mongo() return render_template('alerts/new_alert.html')
async def _get_profile(self, ctx): """See your player profile, balances, current location and inventory.""" player = Player(ctx.message.author.id) inventory_list = player.get_inventory() balances = player.get_balance() location = Location(player.current_location) stores = self.stores.at_location(player.current_location) stores_str = '' for store in stores: if store.location.location_id == player.current_location: if store != stores[-1]: stores_str = stores_str + store.name + ', ' else: stores_str = stores_str + store.name embed = discord.Embed(title='Profile', description='Current Location: ' + location.name, colour=discord.Colour.gold()) if stores_str != '': embed.add_field(name='Stores:', value=stores_str, inline=False) inventory_str = '' if len(inventory_list) > 0: for inventory in inventory_list: item_object = Item(inventory['id']) inventory_str = inventory_str + item_object.emoji + '(' + str( inventory['count']) + ') ' + ' ' + item_object.name + '\n' else: inventory_str = 'Empty Inventory' embed.add_field(name='Bank Balance:', value=':moneybag:' + '{:20,.0f}'.format(balances['bank'])) embed.add_field(name='Cash Balance:', value=':moneybag:' + '{:20,.0f}'.format(balances['wallet'])) embed.add_field(name='Inventory', value=inventory_str, inline=False) embed.set_author(name=ctx.message.author.display_name, icon_url=ctx.message.author.avatar_url) embed.set_thumbnail(url=ctx.message.author.avatar_url) return await ctx.send(embed=embed)
def get_items(self, json_response): items = [] if json_response is not None and json_response['Success'] == True: for product in json_response['Bundles']: product = product['Products'][0] item = Item( product_code=product['Stockcode'], barcode=product['Barcode'], store=constants.WOOLWORTHS, name=product['Name'], price=product['Price'], product_url= "https://www.woolworths.com.au/shop/productdetails/{}/{}". format(product['Stockcode'], product['UrlFriendlyName']), image_url=product['MediumImageFile'], category=product['AdditionalAttributes'] ['piesdepartmentnamesjson'], sub_category=product['AdditionalAttributes'] ['piessubcategorynamesjson']) items.append(item) return items
def add_item(self, item): self.cart.append(Item(item, 0))
def create_item(self, name, price, billing_method, special, datastore): item = Item(name, price, billing_method, special) datastore.set('itemdetails:' + name, item) return item
async def _set_item_description(self, ctx, item_id: int = 0, *, description: str = ''): item_object = Item(item_id) item_object.edit('description', description) await ctx.send('Description Updated. ' + str(item_object.description))
async def _set_item_price_max(self, ctx, item_id: int = 0, price_max: int = 0): item_object = Item(item_id) item_object.edit('price_max', price_max) await ctx.send('Max Price Updated. ' + str(item_object.price_max))
async def _set_item_price_min(self, ctx, item_id: int = 0, price_min: int = 0): print(item_id) item_object = Item(item_id) item_object.edit('price_min', price_min) await ctx.send('Min Price Updated. ' + str(item_object.price_min))
def add_item_w_price(self, item, price): self.cart.append(Item(item, price))
def __post_init__(self): self.item = Item.get_by_id(self.item_id) self.user = User.find_by_email(self.user_email)