|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.templating import Jinja2Templates
|
|
import dataset
|
|
import asyncio
|
|
from datetime import datetime
|
|
|
|
app = FastAPI(title="RSS Feed Manager")
|
|
|
|
# Database setup
|
|
db = dataset.connect('sqlite:///feeds.db')
|
|
|
|
# Templates setup
|
|
templates = Jinja2Templates(directory="templates")
|
|
|
|
# Import routers
|
|
from routers import router as manage_router, run_sync_task
|
|
|
|
app.include_router(manage_router)
|
|
|
|
@app.on_event("startup")
|
|
async def startup_event():
|
|
# Ensure feeds table exists
|
|
feeds_table = db['feeds']
|
|
# Start background sync task
|
|
asyncio.create_task(hourly_sync_task())
|
|
|
|
async def hourly_sync_task():
|
|
while True:
|
|
await asyncio.sleep(3600) # Wait 1 hour
|
|
try:
|
|
await run_sync_task()
|
|
except Exception as e:
|
|
print(f"Error in hourly sync: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run(app, host="127.0.0.1", port=8592)
|