add FastAPI
This commit is contained in:
38
archive/products_sold_parser.py
Normal file
38
archive/products_sold_parser.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import pandas as pd
|
||||
from db_bk.models import Order, ProductsSold
|
||||
|
||||
import os
|
||||
|
||||
|
||||
def parse_csv_to_products_sold(file_path):
|
||||
products_sold = []
|
||||
df = pd.read_csv(file_path, delimiter=';', encoding='cp1252', date_format='%d/%m/%Y')
|
||||
|
||||
for _, row in df.iterrows():
|
||||
ps = ProductsSold(
|
||||
product_id=row['Código produto'],
|
||||
order_id=row['Código pedido'],
|
||||
name=row['Nome produto'],
|
||||
price=row['Preço venda'],
|
||||
quantity=['Quantidade'],
|
||||
reference=row['Referência'],
|
||||
additional_information=row['Informação adicional']
|
||||
)
|
||||
products_sold.append(ps)
|
||||
return products_sold
|
||||
|
||||
|
||||
def load_products_sold_csv(directory_path):
|
||||
all_products_sold = []
|
||||
|
||||
for filename in os.listdir(directory_path):
|
||||
if filename.endswith('.csv'):
|
||||
file_path = os.path.join(directory_path, filename)
|
||||
orders = parse_csv_to_products_sold(file_path)
|
||||
all_products_sold.extend(orders)
|
||||
|
||||
for ps in all_products_sold:
|
||||
print(ps.product_id, ps.price, ps.name)
|
||||
|
||||
|
||||
load_products_sold_csv('../csv/tray-products-sold/')
|
||||
Reference in New Issue
Block a user