Automatic Output to Results Folder - Implementation Summary

Overview

Both scan_starred_repos.py and repo_recommender.py have been updated to automatically save their outputs to the results/ folder with timestamped filenames.

Changes Made

1. Scanner Script (scripts/scan_starred_repos.py)

  • Default Output Location: Automatically generates output filename in results/ folder if not specified
  • Filename Format: results/starred_repos_{username}_{timestamp}.json
  • Timestamp Format: YYYYMMDD_HHMMSS (UTC timezone-aware)
  • Behavior:
    • If --output is not specified, automatically generates a timestamped filename
    • If --output is specified, uses the provided path
    • Creates results/ directory if it doesn’t exist

Example Usage:

# Automatic output to results/
python3 scripts/scan_starred_repos.py --enhance-description --limit 50

# Custom output path (still works)
python3 scripts/scan_starred_repos.py --output custom/path/repos.json

2. Recommender Script (scripts/repo_recommender.py)

  • Default Input Location: Now looks for starred repos in results/ folder by default
  • Default Output Location: Automatically generates output filename in results/ folder if not specified
  • Filename Format: results/recommendations_{timestamp}.{ext} (ext = md or txt based on format)
  • Timestamp Format: YYYYMMDD_HHMMSS (UTC timezone-aware)
  • Behavior:
    • Saves report to timestamped file in results/
    • Also prints a preview to stdout for immediate viewing
    • Creates results/ directory if it doesn’t exist

Example Usage:

# Automatic output to results/
python3 scripts/repo_recommender.py --min-score 30

# Specify starred repos file and custom output
python3 scripts/repo_recommender.py --starred-repos custom/repos.json --output custom/report.md

3. .gitignore Updates

  • Added results/ directory to .gitignore
  • Added !results/.gitkeep to preserve directory structure
  • All generated files in results/ are ignored by git

4. Directory Structure

results/
β”œβ”€β”€ .gitkeep                                    # Tracked by git to preserve directory
β”œβ”€β”€ starred_repos_authenticated_user_YYYYMMDD_HHMMSS.json  # Auto-generated (ignored)
└── recommendations_YYYYMMDD_HHMMSS.md          # Auto-generated (ignored)

Benefits

  1. Organization: All generated outputs are centralized in one location
  2. Version Control: Outputs are automatically ignored by git while the directory structure is preserved
  3. Timestamping: Easy to track when each analysis was performed
  4. Backwards Compatible: Custom output paths still work if specified
  5. No Manual Configuration: Works out of the box without user intervention

Technical Details

Deprecated Function Fixes

  • Replaced datetime.utcnow() with datetime.now(timezone.utc) to comply with Python deprecation warnings
  • Ensures timezone-aware datetime objects for better accuracy

Error Handling

  • Both scripts create the results/ directory automatically if it doesn’t exist
  • Uses os.makedirs(output_dir, exist_ok=True) to prevent errors if directory already exists

Testing

Both scripts have been tested and confirmed working:

  • βœ… Scanner creates timestamped JSON files in results/
  • βœ… Recommender creates timestamped markdown reports in results/
  • βœ… Directory is created automatically if missing
  • βœ… .gitignore properly excludes generated files
  • βœ… .gitkeep preserves directory structure in git

Migration Notes

If you have existing outputs in other locations:

  • Old files in repos/ or data/ remain unaffected
  • You can continue using custom paths with --output flag
  • Consider moving important outputs to results/ for consistency

Back to top

Β© {{ site.time | date: '%Y' }} AI Tools Collection. Licensed under MPL 2.0