def get_storeid(self): session = orm.loadSession() for result in session.query(orm.Store).filter(orm.Store.name == self._store).limit(1): storeid = result.id return storeid
except sqlalchemy.exc.IntegrityError as ex: print ex session.rollback() for image in current_product.images: productimage = orm.ProductImage(product.id, image) session.add(productimage) try: session.commit() except sqlalchemy.exc.IntegrityError as ex: print ex session.rollback() # def adduserproducts(session): # db_products = session.query(Product).all() # for product in db_products: # userproduct = UserProduct(product.userid, product.id) # session.add(userproduct) # try: # session.commit() # except sqlalchemy.exc.IntegrityError as ex: # print ex # session.rollback() if __name__ == "__main__": session = orm.loadSession() check_double_products(session) #addproductimages(session) # adduserproducts(session)
def main(): """ Main function """ stores = ['zalando', 'bijenkorf', 'asos'] actions = ['brands', 'new', 'all', 'test'] parser = ArgumentParser() parser.add_argument("-s", "--store", dest="store", default=None, choices=stores, help="Store") parser.add_argument("-a", "--action", dest="action", default=None, choices=actions, help="Action") parser.add_argument("-l", "--link", dest="link", default=None, help="Link") args = parser.parse_args() session = orm.loadSession() logger.debug('> Loading session..') if args.link is not None: if 'zalando.' in args.link or 'zln.do' in args.link: tracker = zalando.ZalandoTracker(session) elif 'bijenkorf' in args.link: tracker = bijenkorf.BijenkorfTracker(session) elif 'asos.' in args.link: tracker = asos.AsosTracker(session) else: logger.error('Tracker not available') sys.exit() itemid = tracker._get_item_id(args.link) if itemid: item = tracker._get_item(itemid) if item is not None: logger.info("< Found " + str(item) + " in DB") else: logger.warning("< No item found! Need to parse") item = tracker._get_item_data(args.link) if item: logger.info("< Found " + str(item) + "") else: logger.error("< No item found") else: logger.error('< Item ID not found') elif args.store is not None and args.action is not None: tracker = get_tracker(session, args.store) if args.action == 'brands': tracker._set_brands(session, insert=True) elif args.action == 'new': tracker._get_new_items(session) elif args.action == 'all': tracker._get_all_items(session) else: logger.error('< Unknown action. Exiting') sys.exit() else: limit = 5 tracker = zalando.ZalandoTracker(session) items = tracker.get_new_items() print items #get_all_items_in_db(session, limit) #logger.error('< Nothing to do. Use -h to show the help') session.close()