File size: 816 Bytes
cad0e2e 2ec0990 6e3bc3c 2ec0990 6e3bc3c 3be496d cad0e2e 6eae0b8 37c8516 2ec0990 37c8516 2ec0990 37c8516 2ec0990 37c8516 2ec0990 cad0e2e 3be496d 2ec0990 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import os
from fastapi import APIRouter
from dotenv import load_dotenv
from redis_client import redis_client as r
load_dotenv()
router = APIRouter()
@router.get("/news/category/{category}")
def get_cached_articles_by_category(category: str, limit: int):
try:
article_ids = list(r.smembers(f"category:{category}"))[:limit]
articles = []
for article_id in article_ids:
article_data = r.hgetall(f"article:{article_id}")
if article_data:
articles.append(article_data)
return articles
except Exception as e:
print(f"[ERROR] Failed to fetch cached articles: {e}")
return {"error": "Failed to fetch articles from cache."}
@router.get("/")
async def root():
return {"message": "LucidFeed backend is up and running!"} |