Skip to content

Commit 3f73abb

Browse files
author
SM_SAYEED
committed
auto-logging enabled
1 parent c8624a0 commit 3f73abb

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

app.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def auto_import_uploads():
3131
table_name = filename.replace('.', '_').replace('-', '_').replace('/', '_').replace('\\', '_')
3232

3333
try:
34+
# Load data
3435
if ext == 'csv':
3536
df = pd.read_csv(filepath)
3637
elif ext == 'npy':
@@ -43,13 +44,34 @@ def auto_import_uploads():
4344
else:
4445
df = pd.DataFrame(arr)
4546
else:
46-
continue # skip unsupported NPY format
47+
continue # unsupported NPY format
4748
else:
4849
continue
4950

51+
# Write to SQLite
5052
with sqlite3.connect(DB_NAME) as conn:
5153
df.to_sql(table_name, conn, if_exists='replace', index=False)
52-
print(f"Imported: {filename} → table '{table_name}'")
54+
55+
print(f"Imported: {filename} as table '{table_name}'")
56+
57+
# Auto-log into uploads_log if possible
58+
rel_path = os.path.relpath(filepath, UPLOAD_FOLDER)
59+
parts = rel_path.split(os.sep)
60+
61+
if len(parts) >= 3:
62+
property_name = parts[0]
63+
tab = parts[1]
64+
file_name = parts[2]
65+
with sqlite3.connect(DB_NAME) as conn:
66+
c = conn.cursor()
67+
c.execute("""
68+
INSERT OR IGNORE INTO uploads_log (property, tab, filename, uploaded_at)
69+
VALUES (?, ?, ?, ?)
70+
""", (property_name, tab, file_name, datetime.datetime.now().isoformat()))
71+
conn.commit()
72+
print(f"Logged {file_name} to uploads_log.")
73+
else:
74+
print(f"Skipped logging for {filename} (not in expected folder structure).")
5375

5476
except Exception as e:
5577
print(f"Failed to import {filename}: {e}")

0 commit comments

Comments
 (0)