add FastAPI
This commit is contained in:
0
archive/__init__.py
Normal file
0
archive/__init__.py
Normal file
46
archive/order_parser.py
Normal file
46
archive/order_parser.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import pandas as pd
|
||||
from db_bk.models import Order
|
||||
|
||||
import os
|
||||
|
||||
|
||||
def parse_csv_to_orders(file_path):
|
||||
orders = []
|
||||
df = pd.read_csv(file_path, delimiter=';', encoding='cp1252', date_format='%d/%m/%Y')
|
||||
|
||||
for _, row in df.iterrows():
|
||||
print(row['Status pedido'])
|
||||
order = Order(
|
||||
id=row['Pedido'],
|
||||
date=row['Data'],
|
||||
partial_total=row['Subtotal produtos'],
|
||||
taxes=row['Impostos'],
|
||||
point_sale=row['Canal de venda'],
|
||||
shipment=row['Frete tipo'],
|
||||
shipment_value=row['Frete valor'],
|
||||
payment_form=row['Pagamento tipo'],
|
||||
payment_date=row['Pagamento data'],
|
||||
shipment_date=row['Envio data'],
|
||||
access_code=row['Envio codigo'],
|
||||
store_note=row['Obs. loja'],
|
||||
status=row['Status pedido'],
|
||||
discount_coupon=row['Cupom desconto']
|
||||
)
|
||||
orders.append(order)
|
||||
return orders
|
||||
|
||||
|
||||
def load_orders_csv(directory_path):
|
||||
all_orders = []
|
||||
|
||||
for filename in os.listdir(directory_path):
|
||||
if filename.endswith('.csv'):
|
||||
file_path = os.path.join(directory_path, filename)
|
||||
orders = parse_csv_to_orders(file_path)
|
||||
all_orders.extend(orders)
|
||||
|
||||
for order in all_orders:
|
||||
print(order.id, order.date, order.status)
|
||||
|
||||
|
||||
load_orders_csv('../csv/tray-orders/')
|
||||
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