Пример #1
0
 def get(self, product_id_string):
     if product_id_string.isdigit():
         product_id = int(product_id_string)
         product = Product.getProductById(product_id)
         subproducts = Product.getSubProducts(product_id)
         self.userrender("userproduct.html", product = product, subproducts = subproducts)
     else:
         self.redirect('/')
Пример #2
0
 def post(self, product_id_string):
     if product_id_string.isdigit() and self.checkAdminCookie():
         product_id = int(product_id_string)
         value = self.request.get("value")
         position = self.request.get("position")
         position = int(position)
         Product.addSubProduct(product_id, value, position)
         self.redirect("/admin/product/%s/addsubproduct" % product_id_string)
     else:
         self.redirect("/admin/index")
Пример #3
0
 def get(self, product_id_string):
     if product_id_string.isdigit() and self.checkAdminCookie():
         product_id = int(product_id_string)
         product = Product.getProductById(product_id)
         subproducts = Product.getSubProducts(product_id)
         self.adminrender("admineditsubproduct.html",
                          product = product,
                          subproducts = subproducts)
     else:
         self.redirect("/admin/index")
Пример #4
0
def add_product():
	from database import Product, Supplier, Supplier_product
	#try:
	
	p_category = request.form['category']
	p_sub_category = request.form['sub_category']
	p_name = request.form['name']
	p_price = request.form['price']
	gst = request.form['gst']
	product_base_margin = request.form['base_margin']
	p_sale_price = request.form['sale_price']
	sid = request.form['suppplier']
	
	pid = Product.query.order_by(desc(Product.pid)).limit(1).all()
	pid = pid[0]
	pid = pid.pid 
	prefix = pid[:1]
	postfix = int(pid[1:])
	postfix = postfix + 1
	pid = prefix + str(postfix)
		
		
	#Create a product object to insert into the Product table
	product = Product(pid, p_category, p_sub_category, p_name, p_price,product_base_margin, p_sale_price, sid)
	
	#get supplier obj from database 
	supp = Supplier.query.filter_by(sid = sid).first()
	supplier_product = Supplier_product( product, supp)
	
	db.session.add(product)
	db.session.add(supplier_product)
	
	db.session.commit()
		
	return 'product record added successfully'
Пример #5
0
    def process_item(self, item: OlxProduct, spider):
        product = Product(title=item.get('title'),
                          olx_id=item.get('id'),
                          keyword=item.get('keyword'),
                          description=item.get('description'),
                          price=item.get('price'),
                          city=item.get('city'),
                          zip=item.get('zip'),
                          region=item.get('region'),
                          image=item.get('image'),
                          url=item.get('url'),
                          date_time=item.get('date_time'),
                          is_new=not item.get('is_new'))

        is_already_registered = session \
                                    .query(func.count(Product.id)) \
                                    .filter(Product.olx_id == product.olx_id) \
                                    .scalar() != 0

        if is_already_registered:
            logging.warning("Skipping product, already inserted")
            raise DropItem()

        session.add(product)
        session.commit()

        return item
Пример #6
0
    def parse(self, response: HtmlResponse):

        items = response.css('#main-ad-list').css(
            '.item:not(.list_native):not(.yap-loaded)')

        new_item_count = 0

        for item in items:
            attrib = item.attrib
            id = attrib['data-list_id']

            product = Product.get_by_olx_id(int(id))

            if product is not None:
                continue

            new_item_count = new_item_count + 1

            url: str = item.css('.OLXad-list-link::attr(href)').get()
            if url is None:
                url = item.css('.OLXad-list-link-featured::attr(href)').get()

            yield response.follow(url,
                                  callback=self.parse_item,
                                  meta=response.meta.copy())

        if new_item_count > 0:
            for next_link in response.css('a.link[rel="next"]'):
                yield response.follow(next_link,
                                      callback=self.parse,
                                      meta=response.meta)
Пример #7
0
def add_product(description, product_id=None, status='in_stock'):
    if not product_id:
        product_id = uuid4().hex
    db.add(
        Product(product_id=product_id,
                description=description,
                creator_id=get_config(key='node_identifier'),
                status=status))
    db.commit()
Пример #8
0
 def get(self,product_id_string):
     if product_id_string.isdigit():
         product_id = int(product_id_string)
         product = Product.getProductById(product_id)
         category = Category.getCategoryById(product.category.id())
         categories = Category.getAllCategories()
         self.adminrender("admineditproduct.html",
                          product = product,
                          category = category,
                          categories = categories)
     else:
         self.redirect("/admin/index")
Пример #9
0
def choose_product(cnx, cat):
    """
    Prints a list of products within a category, and asks
    the user to choose between them.
    """
    prods = Product.get_products(cnx, cat, 30)

    print("Choissez un produit :")
    for num, prod in enumerate(prods):
        print("[{}] {}".format(str(num + 1).zfill(2), prod.name))
    chosen_prod = get_number("? ", range(1, 31)) - 1

    return prods[chosen_prod]
Пример #10
0
 def post(self,product_id_string):
     if product_id_string.isdigit() and self.checkAdminCookie():
         product_id = int(product_id_string)
         name = self.request.get("name")
         category = self.request.get("category")
         price = self.request.get("price")
         description = self.request.get("description")
         pictureurl = self.request.get("pictureurl")
         position = self.request.get("position")
         showcaseposition = self.request.get("showcaseposition")
         try:
             price = int(price)
             position = int(position)
             showcaseposition = int(showcaseposition)
         except ValueError:
             price = 0
             position = -1
             showcaseposition = -1
         Product.editProduct(product_id, name, price, category, description, pictureurl, position, showcaseposition)
         self.redirect("/admin/product/editproduct/%s" % product_id_string)
     else:
         self.redirect("/admin/index")
Пример #11
0
 def post(self):
     if self.checkAdminCookie():
         name = self.request.get("name")
         category = self.request.get("category")
         price = self.request.get("price")
         try:
             price = int(price)
         except ValueError:
             price = 0
         product_key = Product.addProduct(name, price, category)
         self.redirect("/admin/product/editproduct/%s" % product_key.id())
     else:
         self.redirect("/admin/login")
Пример #12
0
    def set_data_for(self, *args):

        if args:
            reports = []
            for prod in Product.all():
                try:
                    reports.append(
                        Report.filter(Report.product == prod, Report.date > args[0][
                            0], Report.date < args[0][1]).order_by(Report.date.desc()).get())
                except:
                    pass
            self.data = [(rap.product.name, rap.remaining,
                          rap.selling_price, rap.remaining * rap.selling_price)
                         for rap in reports]
Пример #13
0
    def scrape(self, cnx):
        """
        This function scrapes all it can scrape from the API, first
        the categories then all the usable products in them. It removes
        the category if it turns out to be empty once all the useless
        products weeded out (like the ones without a nutriscore or a
        name).
        """
        logging.info("Getting and adding category info")
        categories, categories_name = self.scrape_categories()
        Category.add_bulk(cnx, categories_name)

        logging.info("Getting and adding product info.")
        for category_json in categories:
            category = Category.from_name(cnx, category_json["name"])
            products = self.scrape_products(category_json, category.id)

            # We only register the products if there is 2 or more products
            # after they have been filtered, or else there is no point.
            # If there is no point we might as well remove the category.
            if len(products) > 1:
                Product.add_products(cnx, products)
            else:
                category.remove(cnx)
Пример #14
0
def send_notifications():
    new_products = Product.get_new()
    telegram = TelegramBot()

    for product in new_products:
        p: Product = product
        try:
            telegram.send_notification(p.image, p.title, p.description,
                                       p.price, p.city, p.region, p.url)
            p.is_new = False
            session.commit()
        except:
            logging.exception(
                f"Error while notifying user about product {p.olx_id} - {p.title}"
            )
Пример #15
0
    def set_data_for(self,  on, end):

        if on:
            reports = []
            for prod in Product.all():
                try:
                    reports.append(Reports.select().where(Reports.product == prod,
                                                          Reports.date >= on,
                                                          Reports.date <= end)
                                   .order_by(Reports.date.desc())
                                   .get())
                except:
                    pass
            self.data = [(rep.store.name, rep.product.code, rep.product.name, rep.remaining)
                         for rep in reports]
Пример #16
0
    def set_data_for(self, *args):

        if args:
            reports = []
            for prod in Product.all():
                try:
                    reports.append(
                        Report.filter(Report.product == prod,
                                      Report.date > args[0][0],
                                      Report.date < args[0][1]).order_by(
                                          Report.date.desc()).get())
                except:
                    pass
            self.data = [(rap.product.name, rap.remaining, rap.selling_price,
                          rap.remaining * rap.selling_price)
                         for rap in reports]
Пример #17
0
    def _cmd_add(self, internal_name):
        market_name = rlinput("销售品名(打在检验报告上的名字,例如‘8G04建业’的销售名为8G 04):\n >>>")
        conf = self._input_kind()
        viscosity = self._input_number("粘度值:")
        viscosity_width = self._input_number("粘度上下幅度:")

        product_obj = Product(internal_name=internal_name,
                              market_name=market_name,
                              template=conf['slug'],
                              viscosity=int(viscosity),
                              viscosity_width=int(viscosity_width))
        db.insert_product(product_obj)
        db.insert_product_to_xlsx(product_obj,
                                  '%s/data/database.xlsx' % self.app_path,
                                  'products')
        print("已经插入新的条目到products数据表")
        return product_obj
Пример #18
0
 def createProduct(self, product, user):
     DBSession = sessionmaker(bind=engine)
     session = DBSession()
     catalog = session.query(Catalog).filter_by(
         id=product['catalog_id']).one()
     newProduct = Product(images=product['images'],
                          header=product['header'],
                          model=product['model'],
                          price=product['price'],
                          brand=product['brand'],
                          description=product['description'],
                          specs=product['specs'],
                          catalog_id=catalog.id,
                          user_id=user)
     try:
         session.add(newProduct)
         session.commit()
         return "New product created"
     except exc.SQLAlchemyError:
         return "Product not created"
Пример #19
0
def init_product_data(file, sheet):
    """ 从 database.xlsx 读取数据 """
    wb = load_workbook(filename=file)
    ws = wb[sheet]
    for row in ws['A2:J{}'.format(ws.max_row)]:
        (internal_name, template, viscosity, viscosity_width, market_name,
         category, part_a, part_b, ratio,
         color) = [cell.value for cell in row]
        if internal_name:
            product = Product(internal_name=internal_name,
                              template=template,
                              viscosity=viscosity,
                              viscosity_width=viscosity_width,
                              market_name=market_name,
                              category=category,
                              part_a=part_a,
                              part_b=part_b,
                              ratio=ratio,
                              color=color)
            db_session.add(product)
    db_session.commit()
    print("插入了 %s 行数据到data/database.sdb3." % str(ws.max_row - 1))
Пример #20
0
 def get(self):
     products = Product.getAllProductsOrderShowcaseposition()
     self.userrender("userindex.html", products = products)
Пример #21
0
            print(IOError)

# Add products
for product in products_dict:
    product_query = session.query(Product).filter_by(
        model=product['model']).count()
    if product_query:
        print("product exists")
        continue
    else:
        try:
            catalog_id = session.query(Catalog).filter_by(
                name=product['category']).one().id
            images = ""
            for i in product['images']:
                images += i + ","
            session.add(
                Product(images=images,
                        header=product['header'],
                        model=product['model'],
                        price=product['price'],
                        brand=product['brand'],
                        description=product['description'],
                        specs=product['specs'],
                        catalog_id=catalog_id,
                        user_id=1))
            session.commit()
            print("Model added %s") % product['model']
        except IOError:
            print(IOError)
Пример #22
0
def _check_pending_products():
    query = Product.get_new().count()
    if query != 0:
        logging.getLogger(__name__).error(
            "Pending products during start of spider")
Пример #23
0
 def post(self):
     """New Shops"""
     product = Product(id=str(uuid.uuid4()), **api.payload)
     save(product)
     return product, 201
Пример #24
0
 def post(self):
     self.set_header("Content-Type", "application/json")
     to_add = self.json_args["title"]
     new_product = Product(title=to_add)
     new_product.add()
     self.write('{"message":" Added: ' + to_add + '"}')
Пример #25
0
 def get(self):
     products = Product.getAllProducts()
     self.adminrender("admineditproducts.html", products = products)