feat(modefied)
This commit is contained in:
1 parent
d705f2f9d3
commit
e3110c3897
12 files changed
+237
-63
No files matched your search
+13
-16
@@ -2,14 +2,14 @@ import re
|
||||
import sqlite3
|
||||
from loguru import logger as log
|
||||
|
||||
def add_category(conn, name, description=None, parent_id=None, image_path=None, page_number=1):
|
||||
def add_category(conn, name, description=None, parent_id=None, image_path=None):
|
||||
cursor = conn.cursor()
|
||||
|
||||
try:
|
||||
cursor.execute('''
|
||||
INSERT OR IGNORE INTO categories (name, description, parent_id, image_path, page_number)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
''', (name, description, parent_id, image_path, page_number))
|
||||
INSERT OR IGNORE INTO categories (name, description, parent_id, image_path)
|
||||
VALUES (?, ?, ?, ?)
|
||||
''', (name, description, parent_id, image_path))
|
||||
|
||||
cursor.execute('SELECT id FROM categories WHERE name = ?', (name,))
|
||||
result = cursor.fetchone()
|
||||
@@ -59,8 +59,8 @@ def parse_product_data(product_text):
|
||||
'stiffness_class': stiffness_class
|
||||
}
|
||||
|
||||
def add_product(conn, product_text, category_id, image_path=None, page_number=1):
|
||||
"""Добавление товара с парсингом параметров, изображением и номером страницы"""
|
||||
def add_product(conn, product_text, category_id, image_path=None):
|
||||
"""Добавление товара с парсингом параметров и изображением"""
|
||||
cursor = conn.cursor()
|
||||
|
||||
product_data = parse_product_data(product_text)
|
||||
@@ -70,8 +70,8 @@ def add_product(conn, product_text, category_id, image_path=None, page_number=1)
|
||||
INSERT INTO products (
|
||||
name, full_name, description, category_id,
|
||||
diameter, wall_thickness, length, color,
|
||||
application_type, stiffness_class, image_path, page_number
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
application_type, stiffness_class, image_path
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
''', (
|
||||
product_data['short_name'],
|
||||
product_data['full_name'],
|
||||
@@ -83,8 +83,7 @@ def add_product(conn, product_text, category_id, image_path=None, page_number=1)
|
||||
product_data['color'],
|
||||
product_data['application_type'],
|
||||
product_data['stiffness_class'],
|
||||
image_path,
|
||||
page_number
|
||||
image_path
|
||||
))
|
||||
|
||||
product_id = cursor.lastrowid
|
||||
@@ -122,10 +121,9 @@ def get_categories_by_page(conn, page_number=1, items_per_page=9):
|
||||
|
||||
cursor.execute('''
|
||||
SELECT * FROM categories
|
||||
WHERE page_number = ?
|
||||
ORDER BY id
|
||||
LIMIT ? OFFSET ?
|
||||
''', (page_number, items_per_page, offset))
|
||||
''', (items_per_page, offset))
|
||||
|
||||
return cursor.fetchall()
|
||||
|
||||
@@ -137,17 +135,16 @@ def get_products_by_page(conn, page_number=1, items_per_page=9, category_id=None
|
||||
if category_id:
|
||||
cursor.execute('''
|
||||
SELECT * FROM products
|
||||
WHERE page_number = ? AND category_id = ?
|
||||
WHERE category_id = ?
|
||||
ORDER BY id
|
||||
LIMIT ? OFFSET ?
|
||||
''', (page_number, category_id, items_per_page, offset))
|
||||
''', (category_id, items_per_page, offset))
|
||||
else:
|
||||
cursor.execute('''
|
||||
SELECT * FROM products
|
||||
WHERE page_number = ?
|
||||
ORDER BY id
|
||||
LIMIT ? OFFSET ?
|
||||
''', (page_number, items_per_page, offset))
|
||||
''', (items_per_page, offset))
|
||||
|
||||
return cursor.fetchall()
|
||||
|
||||
|
||||
Reference in new issue
Block a user