Files
DS_TASK_AI_VIEWS/simple_main.py
T

52 lines
1.5 KiB
Python

"""Simple FastAPI server for testing"""
from fastapi import FastAPI
import feedparser
from datetime import datetime
app = FastAPI(title="DS Task AI News - Simple Version")
@app.get("/")
async def root():
return {"message": "DS Task AI News API is running!", "status": "healthy"}
@app.get("/test-rss")
async def test_rss():
"""Test RSS fetching"""
feeds = [
"https://rss.cnn.com/rss/edition.rss",
"https://feeds.bbci.co.uk/news/rss.xml"
]
results = []
for feed_url in feeds:
try:
feed = feedparser.parse(feed_url)
result = {
"url": feed_url,
"title": feed.feed.get('title', 'Unknown'),
"entries_count": len(feed.entries),
"success": True
}
if len(feed.entries) > 0:
result["sample_article"] = {
"title": feed.entries[0].get('title', 'No title'),
"published": feed.entries[0].get('published', 'No date'),
"link": feed.entries[0].get('link', 'No link')
}
results.append(result)
except Exception as e:
results.append({
"url": feed_url,
"success": False,
"error": str(e)
})
return {"results": results, "timestamp": datetime.now().isoformat()}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)