예제 #1
0
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))
예제 #2
0
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))
        ])
예제 #3
0
 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
예제 #4
0
def open_storage():
        return StorageManager(path=STORAGE_PATH)
예제 #5
0
def get_storage(path_='storage/storage.fs'):
    return StorageManager(path_)
예제 #6
0
def root_factory(request):
    conn = get_connection(request)
    return StorageManager(connection=conn)