This commit is contained in:
2025-05-20 16:24:55 +07:00
parent 8f9e4cf14c
commit e5276cb5dc
6 changed files with 158 additions and 0 deletions

30
.gitignore vendored
View File

@@ -160,3 +160,33 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/ #.idea/
# my list
**/test/
**/incoming_files/
**/media/
**/logs/
**/processed_files/
incoming_files/
media/
processed_files/
test/
/static/
# Игнорировать все папки 'old' в любом месте проекта
**/old/
# Дополнительно: игнорировать все содержимое таких папок
**/old/*
# Дополнительно: игнорировать даже скрытые файлы в таких папках
**/old/.*
# Дополнительно: игнорировать папки с другим регистром (Old, OLD и т.д.)
**/[oO][lL][dD]/
.codegpt
# LibreOffice / OpenOffice temporary files
.~lock.*#
*.csv

BIN
cars_database.db Normal file

Binary file not shown.

View File

@@ -0,0 +1,25 @@
import pandas as pd
from models import Car, Category
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite:///cars_database.db')
Session = sessionmaker(bind=engine)
session = Session()
rows = []
cars = session.query(Car).all()
for car in cars:
car_data = {k: v for k, v in car.__dict__.items() if not k.startswith('_')}
# Названия категорий через ;
category_names = [c.name for c in car.categories]
car_data['category_names'] = '; '.join(category_names)
rows.append(car_data)
df = pd.DataFrame(rows)
df.to_csv('cars_with_categories.csv', index=False)
print("✅ cars_with_categories.csv сохранён")
session.close()

32
export_to_excel.py Normal file
View File

@@ -0,0 +1,32 @@
import pandas as pd
from models import Articl, Car, Category, Product
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite:///cars_database.db')
Session = sessionmaker(bind=engine)
session = Session()
models = {
'cars.csv': Car,
'categories.csv': Category,
'products.csv': Product,
'articles.csv': Articl
}
for filename, model in models.items():
records = session.query(model).all()
if not records:
continue
rows = []
for r in records:
row = {k: v for k, v in r.__dict__.items() if not k.startswith('_')}
rows.append(row)
df = pd.DataFrame(rows)
df.to_csv(filename, index=False)
print(f"{filename} сохранён")
session.close()

59
models.py Normal file
View File

@@ -0,0 +1,59 @@
from sqlalchemy import JSON, Column, ForeignKey, Integer, String, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
Base = declarative_base()
class Car(Base):
__tablename__ = 'cars'
ID = Column(Integer, primary_key=True)
vendor = Column(String)
model = Column(String)
year = Column(String)
power = Column(String)
modification = Column(String)
categories = relationship("Category", back_populates="car")
class Category(Base):
__tablename__ = 'categories'
ID = Column(Integer, primary_key=True)
ID_car = Column(Integer, ForeignKey('cars.ID'))
num_category = Column(String)
name = Column(String)
url = Column(String)
car = relationship("Car", back_populates="categories")
products = relationship("Product", back_populates="category")
class Product(Base):
__tablename__ = 'product'
ID = Column(Integer, primary_key=True)
ID_category = Column(Integer, ForeignKey('categories.ID'))
code = Column(String)
img_src = Column(String)
description = Column(String)
info = Column(String)
product_link = Column(String)
category = relationship("Category", back_populates="products")
articls = relationship("Articl", back_populates="product")
class Articl(Base):
__tablename__ = 'articl'
ID = Column(Integer, primary_key=True)
code = Column(String, ForeignKey('product.code'))
json_info = Column(JSON)
product = relationship("Product", back_populates="articls")
engine = create_engine('sqlite:///cars_database.db')
Base.metadata.create_all(engine)

12
requirements.txt Normal file
View File

@@ -0,0 +1,12 @@
et_xmlfile==2.0.0
greenlet==3.2.2
numpy==2.2.6
openpyxl==3.1.5
pandas==2.2.3
python-dateutil==2.9.0.post0
pytz==2025.2
six==1.17.0
SQLAlchemy==2.0.41
typing_extensions==4.13.2
tzdata==2025.2
XlsxWriter==3.2.3