refactor: Update load_scanner_reports with debug logging and robust path resolution

This commit is contained in:
Bobby (aider) 2025-02-12 20:09:36 -08:00
parent f4f7505e5c
commit 5502c54845

View File

@ -13,22 +13,31 @@ def load_scanner_reports(scanner_type: str = None):
list: List of dictionaries containing report information
"""
reports = []
reports_dir = Path("src/reports")
# Get absolute path to reports directory
reports_dir = Path.cwd() / "reports"
# Create reports directory if it doesn't exist
reports_dir.mkdir(parents=True, exist_ok=True)
if reports_dir.exists():
# Print debug info
print(f"Scanning directory: {reports_dir}")
for file in reports_dir.glob("*.csv"):
print(f"Found file: {file.name}") # Debug print
# Get file creation time
created = datetime.fromtimestamp(file.stat().st_ctime)
# If scanner_type is specified, filter based on actual naming patterns
if scanner_type == "technical":
if not (file.name.startswith(("atr_ema_", "sunny_"))):
print(f"Skipping {file.name} - not a technical report") # Debug print
continue
elif scanner_type == "canslim":
if not file.name.startswith("canslim_"):
print(f"Skipping {file.name} - not a CANSLIM report") # Debug print
continue
reports.append({
@ -36,6 +45,10 @@ def load_scanner_reports(scanner_type: str = None):
'path': str(file),
'created': created
})
print(f"Added report: {file.name}") # Debug print
# Print final count
print(f"Found {len(reports)} matching reports")
# Sort by creation time, newest first
return sorted(reports, key=lambda x: x['created'], reverse=True)