empty tabl;e before inserting

celery-integration
peter.fong 9 months ago
parent b70443c839
commit 48266fed67

@ -203,8 +203,15 @@ def getextrapolation(extrapolateYears):
def process_excel(filepath):
df = pd.read_excel(filepath, engine="openpyxl")
df.columns = df.columns.str.strip()
conn, cursor = get_db_connection()
cursor.execute(
"""
truncate table onderhoud
"""
)
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS onderhoud (
@ -227,11 +234,19 @@ def process_excel(filepath):
"""
)
cursor.execute(
"SELECT Object_code, Omschrijving_PO, Vervaldatum FROM onderhoud")
existing_records = set(cursor.fetchall())
for _, row in df.iterrows():
for column in row.index:
if pd.isna(row[column]):
row[column] = ""
record = (row["Object code"],
row["Omschrijving PO"], row["Vervaldatum"])
if record not in existing_records:
cursor.execute(
"""
INSERT INTO onderhoud
@ -256,6 +271,7 @@ def process_excel(filepath):
row["Categorie"],
),
)
existing_records.add(record)
conn.commit()
cursor.close()

Loading…
Cancel
Save