-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.py
More file actions
29 lines (21 loc) · 797 Bytes
/
storage.py
File metadata and controls
29 lines (21 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pandas as pd
import os
DATA_DIR = "data"
PRODUCTS_FILE = f"{DATA_DIR}/products.xlsx"
SALES_FILE = f"{DATA_DIR}/sales.xlsx"
def initialize_files():
os.makedirs(DATA_DIR, exist_ok=True)
if not os.path.exists(PRODUCTS_FILE):
df = pd.DataFrame(columns=["ID", "Name", "Category", "Price", "Quantity"])
df.to_excel(PRODUCTS_FILE, index=False)
if not os.path.exists(SALES_FILE):
df = pd.DataFrame(columns=["SaleID", "ProductID", "Quantity", "TotalPrice", "Date"])
df.to_excel(SALES_FILE, index=False)
def load_products():
return pd.read_excel(PRODUCTS_FILE)
def save_products(df):
df.to_excel(PRODUCTS_FILE, index=False)
def load_sales():
return pd.read_excel(SALES_FILE)
def save_sales(df):
df.to_excel(SALES_FILE, index=False)