def set_package_ratio(): """Walk through products and set `package` and `package_ratio`""" keeper = StorageManager(FileStorage('storage.fs')) products = Product.fetch_all(keeper) for product in products: try: product.package = product.get_package() product.package_ratio = product.package.get_ratio(product.category) print(green(u'Product "{}" updated'.format(product))) except AttributeError, e: print(red(u'{} removed'.format(product))) keeper.delete(product) except PackageLookupError, e: logging.debug(e.message.encode('utf-8')) print(yellow(e.message))
def stats(category_key, days=2): """Show daily statistics for a category""" from prettytable import PrettyTable table = PrettyTable( ['date/time', 'report #', 'product #', 'median', 'min', 'max']) table.align = 'l' dates = get_datetimes(days) keeper = StorageManager(FileStorage('storage.fs')) category = ProductCategory.fetch(category_key, keeper) print(table) for date in dates: table.add_row([ str(date), len(category.get_reports(date)), len(category.products), category.get_price(date), category.get_price(cheap=True), max(category.get_prices(date)) ])
def setUp(self): self.keeper = StorageManager() result = self.keeper.load_fixtures('fixtures.json') transaction.commit() self.report1_key = result['reports'][0].key self.report2_key = result['reports'][1].key
def open_storage(): return StorageManager(path=STORAGE_PATH)
def get_storage(path_='storage/storage.fs'): return StorageManager(path_)
def root_factory(request): conn = get_connection(request) return StorageManager(connection=conn)