mirror of
https://github.com/kennethreitz/kennethreitz.org.git
synced 2026-06-05 22:50:17 +00:00
2ee4b57d77
- Reduced dependencies from 13 to 5 packages (66% reduction) - Removed unused packages: pydantic, fastapi, uvicorn, pygments, boto3, pillow, background, markdown - Kept essential packages: flask, gunicorn, gevent, mistune, pyyaml - Moved docs/ from data/docs/ to root directory for better organization - Updated all internal documentation links to reflect new location 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
"""Content processing core functionality."""
|
|
|
|
import random
|
|
from pathlib import Path
|
|
|
|
|
|
class ContentProcessor:
|
|
"""Process and manage content operations."""
|
|
|
|
def __init__(self, data_dir="data"):
|
|
"""Initialize content processor."""
|
|
self.data_dir = Path(data_dir)
|
|
|
|
def get_random_post(self):
|
|
"""Get a random post from essays."""
|
|
essays_dir = self.data_dir / "essays"
|
|
if not essays_dir.exists():
|
|
return None
|
|
|
|
md_files = list(essays_dir.glob("*.md"))
|
|
if md_files:
|
|
return random.choice(md_files)
|
|
return None
|
|
|
|
def get_random_from_collection(self, collection):
|
|
"""Get a random post from a specific collection."""
|
|
collection_dir = self.data_dir / collection
|
|
if not collection_dir.exists():
|
|
return None
|
|
|
|
md_files = list(collection_dir.glob("**/*.md"))
|
|
md_files = [f for f in md_files if f.name != "index.md"]
|
|
|
|
if md_files:
|
|
return random.choice(md_files)
|
|
return None
|