def get_shops(): # use creds to create a client to interact with the Google Drive API scope = [ 'https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive' ] creds = ServiceAccountCredentials.from_json_keyfile_name( 'VeganPartnersSheetKey.json', scope) client = gspread.authorize(creds) # Find a workbook by name and open the first sheet # Make sure you use the right name here. sheet = client.open("тест таблица").sheet1 full_list = sheet.get_all_values() shop_dict = {} i = 0 current_shop = None while i < len(full_list): row = full_list[i] if row[0] == '': shop_dict[current_shop].item_dict[row[2]] = Item( row[2], row[3], int(row[4]), str(i)) else: shop_dict[row[0]] = Shop( row[0], {row[2]: Item(row[2], row[3], int(row[4]), str(i))}, int(row[1]) / 100) current_shop = row[0] i += 1 return shop_dict
def test_add_item_to_user(self): u = User(first_name="tanawat", last_name="khunlertkit", username="******") item = Item(name="car") self.assertTrue(u.add_to_datastore()) item.put() u.add_item(item) self.assertFalse(u.add_to_datastore()) self.assertEqual(1, len(Item.query().fetch())) u_list = User.query(User.username == "tanawat").fetch() self.assertEqual(1, len(u_list)) self.assertEqual(1, len(u_list[0].items))
def test_calculate_player_stats(self): self.assertEqual( Stats( hp=100, damage=3, armor=30 ), main.calculate_player_stats({ Item(damage=1), Item(damage=2), Item(armor=10), Item(armor=20), }) )
def purchaseGoods(self): stock.displayItems() customerName = input("Enter your name\n") items = [] name = input( "Enter the name of the products you want to buy. Enter -1 to end\n" ) while name != "-1": realItem = stock.getItem(name) if realItem != None: quantity = input("\nEnter quantity\n") item = Item(realItem.name, quantity, realItem.price) items.append(item) else: print("\nItem not found") name = input("\nEnter another product. Enter -1 to end\n") stock.purchaseGoods(customerName, items)
def UpdateSchema(cursor=None, num_updated=0): query = Item.query() to_put = [] res, cursor, more = query.fetch_page(BATCH_SIZE, start_cursor=cursor) for p in res: # In this example, the default values of 0 for num_votes and avg_rating # are acceptable, so we don't need this loop. If we wanted to manually # manipulate property values, it might go something like this: p.create_by = 'Anonymous' to_put.append(p) if to_put: ndb.put_multi(to_put) num_updated += len(to_put) logging.debug('Put %d entities to Datastore for a total of %d', len(to_put), num_updated) deferred.defer(UpdateSchema, cursor=cursor, num_updated=num_updated) else: logging.debug('UpdateSchema complete with %d updates!', num_updated)
def UpdateSchema(cursor=None, num_updated=0): query = Item.query() to_put = [] res, cursor, more = query.fetch_page(BATCH_SIZE, start_cursor=cursor) for p in res: # In this example, the default values of 0 for num_votes and avg_rating # are acceptable, so we don't need this loop. If we wanted to manually # manipulate property values, it might go something like this: p.create_by = 'Anonymous' to_put.append(p) if to_put: ndb.put_multi(to_put) num_updated += len(to_put) logging.debug( 'Put %d entities to Datastore for a total of %d', len(to_put), num_updated) deferred.defer( UpdateSchema, cursor=cursor, num_updated=num_updated) else: logging.debug( 'UpdateSchema complete with %d updates!', num_updated)
from main import db,User,Item,Kit,Climate,Culture db.drop_all() db.create_all() new = User('Stan','Ward') db.session.add(new) new = User('Fred','Flintstone') db.session.add(new) db.session.commit() new = Item('shirt','Stan') db.session.add(new) new = Item('pants','Fred') db.session.add(new) new = Item('belt','Fred') db.session.add(new) db.session.commit() new = Kit(1,'Fred') db.session.add(new) db.session.commit() new = Climate('subarctic') db.session.add(new) new = Climate('arctic') db.session.add(new) db.session.commit() new = Culture('viking') db.session.add(new) new = Culture('pict')
def test_add_item_to_datastore(self): item = Item(name="car") item.put() self.assertEqual(1, len(Item.query().fetch()))
from main import db, Item, Category from datetime import datetime mobile = Category(name="mobile", user_id="admin") redmia1 = Item(brand="Redmi", name="Redmi A1", price=10000, description="simple description", image='https://images-na.ssl-images-amazon.com/images/I/' '81L23OnNA%2BL._SX522_.jpg', category_id=1, user_id="admin") db.session.add(mobile) db.session.add(redmia1) headset = Category(name="headset", user_id="admin") bluetooth = Item(brand="samsung", name="Samsung Level U Bluetooth", price=2399, description="The Samsung Level U Wireless Headset offers a" "Comfortable Fit and More Battery Power so that your day " "is filled with your favourite music", image='https://rukminim1.flixcart.com/image/832/832/jhgl5e80/' 'headphone/t/9/b/samsung-level-u-eo-bg920bbegin-original-' 'imaf5h5qwx37dmca.jpeg?q=70', category_id=2, user_id="admin") db.session.add(headset) db.session.add(bluetooth) db.session.commit() print("created intialized data")
from main import Packer, Bin, Item packer = Packer() # packer.add_bin(Bin('small-envelope', 11.5, 6.125, 0.25, 10)) # packer.add_bin(Bin('large-envelope', 15.0, 12.0, 0.75, 15)) # packer.add_bin(Bin('small-box', 8.625, 5.375, 1.625, 70.0)) # packer.add_bin(Bin('medium-box', 11.0, 8.5, 5.5, 70.0)) # packer.add_bin(Bin('medium-2-box', 13.625, 11.875, 3.375, 70.0)) # packer.add_bin(Bin('large-box', 12.0, 12.0, 5.5, 70.0)) # packer.add_bin(Bin('large-2-box', 23.6875, 11.75, 3.0, 70.0)) packer.add_bin(Bin('Container01', 30, 40, 20, 100)) # packer.add_item(Item('Box01_1', 7, 8, 5, 1)) packer.add_item(Item('Box01_2', 13, 5, 10, 1)) packer.add_item(Item('Box01_2', 13, 5, 10, 1)) packer.add_item(Item('Box01_4', 5, 7, 8, 1)) packer.add_item(Item('Box01_3', 7, 8, 5, 1)) packer.add_item(Item('Box01_5', 3, 1, 5, 1)) packer.add_item(Item('Box01_6', 2, 1, 2, 1)) packer.add_item(Item('Box01_7', 2, 1, 2, 1)) packer.add_item(Item('Box01_8', 2, 1, 2, 1)) packer.add_item(Item('Box01_9', 2, 1, 2, 1)) packer.add_item(Item('Box01_10', 2, 1, 2, 1)) packer.add_item(Item('Box01_11', 2, 1, 2, 1)) packer.add_item(Item('Box01_12', 4, 8, 2, 1)) packer.add_item(Item('Box01_2', 13, 5, 10, 1)) packer.add_item(Item('Box01_2', 13, 5, 10, 1)) packer.add_item(Item('Box01_4', 5, 7, 8, 1)) packer.add_item(Item('Box01_3', 7, 8, 5, 1)) packer.add_item(Item('Box01_5', 3, 1, 5, 1))