72 lines
1.9 KiB
Python
72 lines
1.9 KiB
Python
"""
|
|
List all projects in reverse numerical order (by ID)
|
|
|
|
Usage:
|
|
uv run python scripts/list_projects.py
|
|
"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
project_root = Path(__file__).parent.parent
|
|
sys.path.insert(0, str(project_root))
|
|
|
|
from src.database.session import db_manager
|
|
from src.database.repositories import ProjectRepository
|
|
|
|
try:
|
|
import msvcrt
|
|
except ImportError:
|
|
msvcrt = None
|
|
|
|
|
|
def wait_for_key():
|
|
"""Wait for user to press any key"""
|
|
if msvcrt:
|
|
print("\nPress any key to continue... (Press 'q' to quit)")
|
|
key = msvcrt.getch()
|
|
if key in (b'q', b'Q'):
|
|
return False
|
|
return True
|
|
else:
|
|
response = input("\nPress Enter to continue (or 'q' to quit): ")
|
|
return response.lower() != 'q'
|
|
|
|
|
|
def list_projects():
|
|
"""List all projects in reverse numerical order (by ID)"""
|
|
session = db_manager.get_session()
|
|
try:
|
|
project_repo = ProjectRepository(session)
|
|
projects = project_repo.get_all()
|
|
|
|
if not projects:
|
|
print("No projects found in database")
|
|
return
|
|
|
|
projects_sorted = sorted(projects, key=lambda p: p.id, reverse=True)
|
|
|
|
print(f"\nTotal projects: {len(projects_sorted)}")
|
|
print("=" * 100)
|
|
print(f"{'ID':<6} {'Name':<35} {'Main Keyword':<30} {'Tier':<6} {'User ID':<8} {'Created'}")
|
|
print("=" * 100)
|
|
|
|
batch_size = 10
|
|
for i, project in enumerate(projects_sorted, 1):
|
|
created = project.created_at.strftime("%Y-%m-%d %H:%M:%S")
|
|
print(f"{project.id:<6} {project.name[:34]:<35} {project.main_keyword[:29]:<30} {project.tier:<6} {project.user_id:<8} {created}")
|
|
|
|
if i % batch_size == 0 and i < len(projects_sorted):
|
|
if not wait_for_key():
|
|
break
|
|
|
|
print("=" * 100)
|
|
|
|
finally:
|
|
session.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
list_projects()
|
|
|