Compare commits
No commits in common. "2c340ae2dfc278f7f6ef8a7463e98bdc200afb11" and "83bb62ad32f2b354de9b912ad16d01e942cded59" have entirely different histories.
2c340ae2df
...
83bb62ad32
26
analytics.py
26
analytics.py
@ -158,25 +158,6 @@ def log_file_access(rel_path, filesize, mime, ip_address, user_agent, device_id,
|
||||
return True
|
||||
|
||||
|
||||
def return_folder_today():
|
||||
"""
|
||||
Return only those folder_today entries whose first segment
|
||||
(up to the first '/') is in session['folders'].keys().
|
||||
"""
|
||||
valid_keys = set(session.get('folders', {}).keys())
|
||||
|
||||
filtered = []
|
||||
for entry in folder_today:
|
||||
# get the part before the first slash
|
||||
top_level = entry['rel_path'].split('/', 1)[0]
|
||||
|
||||
# include only if this segment is one of the session keys
|
||||
if top_level in valid_keys:
|
||||
filtered.append(entry)
|
||||
|
||||
return filtered
|
||||
|
||||
|
||||
def return_file_access():
|
||||
"""Return recent file access logs from memory (the last 10 minutes)."""
|
||||
global file_access_temp
|
||||
@ -193,6 +174,13 @@ def return_file_access():
|
||||
return []
|
||||
|
||||
|
||||
def return_folder_today():
|
||||
global folder_today
|
||||
if folder_today:
|
||||
return folder_today
|
||||
else:
|
||||
return []
|
||||
|
||||
def songs_dashboard():
|
||||
# — SESSION & PARAM HANDLING (unchanged) —
|
||||
if 'songs_dashboard_timeframe' not in session:
|
||||
|
||||
@ -3,7 +3,6 @@ import json
|
||||
import sqlite3
|
||||
from datetime import datetime
|
||||
import re
|
||||
import helperfunctions as hf
|
||||
|
||||
SEARCH_DB_NAME = 'search.db'
|
||||
ACCESS_LOG_DB_NAME = 'access_log.db'
|
||||
@ -71,6 +70,51 @@ def get_hit_count(relative_path):
|
||||
return row["hit_count"] if row else 0
|
||||
|
||||
|
||||
def extract_date_from_string(string_with_date):
|
||||
# grab X.Y.Z where X,Y,Z are 1–4 digits
|
||||
m = re.search(r'(\d{1,4}\.\d{1,2}\.\d{1,4})', string_with_date)
|
||||
if not m:
|
||||
return None
|
||||
|
||||
date_str = m.group(1)
|
||||
parts = date_str.split('.')
|
||||
|
||||
# 1) Unambiguous “last group = YYYY”
|
||||
if len(parts) == 3 and len(parts[2]) == 4:
|
||||
fmt = '%d.%m.%Y'
|
||||
|
||||
# 2) Unambiguous “first group = YYYY”
|
||||
elif len(parts) == 3 and len(parts[0]) == 4:
|
||||
fmt = '%Y.%m.%d'
|
||||
|
||||
# 3) Ambiguous “XX.XX.XX” → prefer DD.MM.YY, fallback to YY.MM.DD
|
||||
elif len(parts) == 3 and all(len(p) == 2 for p in parts):
|
||||
# try last-group-as-year first
|
||||
try:
|
||||
dt = datetime.strptime(date_str, '%d.%m.%y')
|
||||
return dt.strftime('%Y-%m-%d')
|
||||
except ValueError:
|
||||
# fallback to first-group-as-year
|
||||
fmt = '%y.%m.%d'
|
||||
|
||||
else:
|
||||
# optional: handle ISO with dashes
|
||||
if '-' in date_str:
|
||||
try:
|
||||
dt = datetime.strptime(date_str, '%Y-%m-%d')
|
||||
return dt.strftime('%Y-%m-%d')
|
||||
except ValueError:
|
||||
return None
|
||||
return None
|
||||
|
||||
# parse with whichever fmt we settled on
|
||||
try:
|
||||
dt = datetime.strptime(date_str, fmt)
|
||||
return dt.strftime('%Y-%m-%d')
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
def updatefileindex():
|
||||
cursor = search_db.cursor()
|
||||
|
||||
@ -171,7 +215,7 @@ def updatefileindex():
|
||||
titel = None
|
||||
name = None
|
||||
|
||||
performance_date = hf.extract_date_from_string(relative_path)
|
||||
performance_date = extract_date_from_string(relative_path)
|
||||
|
||||
scanned_files.append((relative_path, foldername, entry.name, filetype, category, titel, name, performance_date, site, transcript, hit_count))
|
||||
current_keys.add((relative_path, entry.name))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user