Skip to content

Commit 3dfaddf

Browse files
author
SM_SAYEED
committed
result logging initiated
1 parent 41f928a commit 3dfaddf

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

app.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,40 @@ def auto_import_uploads():
7676
except Exception as e:
7777
print(f"Failed to import {filename}: {e}")
7878

79+
def auto_log_material_files():
80+
if not os.path.exists(UPLOAD_FOLDER):
81+
return
82+
83+
all_allowed_exts = ALLOWED_DATASET_EXTENSIONS | ALLOWED_RESULTS_EXTENSIONS | ALLOWED_MUSIC_EXTENSIONS
84+
85+
for root, dirs, files in os.walk(UPLOAD_FOLDER):
86+
for filename in files:
87+
ext = filename.rsplit('.', 1)[-1].lower()
88+
if ext not in all_allowed_exts:
89+
continue
90+
91+
filepath = os.path.join(root, filename)
92+
rel_path = os.path.relpath(filepath, UPLOAD_FOLDER)
93+
parts = rel_path.split(os.sep)
94+
95+
# Skip music uploads under /uploads/clips/
96+
if parts[0] == 'clips':
97+
continue
98+
99+
if len(parts) >= 3:
100+
property_name = parts[0]
101+
tab = parts[1]
102+
file_name = parts[2]
103+
104+
with sqlite3.connect(DB_NAME) as conn:
105+
c = conn.cursor()
106+
c.execute("""
107+
INSERT OR IGNORE INTO uploads_log (property, tab, filename, uploaded_at)
108+
VALUES (?, ?, ?, ?)
109+
""", (property_name, tab, file_name, datetime.datetime.now().isoformat()))
110+
conn.commit()
111+
print(f"Auto-logged: {rel_path}")
112+
79113

80114
# ========== FLASK APP ==========
81115
app = Flask(__name__)
@@ -506,6 +540,8 @@ def delete_dataset_file(property_name, tab, filename):
506540
print(rule.endpoint, rule)
507541

508542
auto_import_uploads()
543+
auto_log_material_files()
544+
509545

510546
# ========== MAIN ==========
511547
if __name__ == '__main__':

0 commit comments

Comments
 (0)