michelerussoAA's picture
Create app.py
512aebf verified
raw
history blame contribute delete
521 Bytes
import threading
from fastapi import FastAPI
from datetime import datetime
from scraper import main # our scraping entrypoint
app = FastAPI()
_started = False
@app.on_event("startup")
def kick_off_scraper():
global _started
if not _started:
_started = True
thread = threading.Thread(target=main, daemon=True)
thread.start()
@app.get("/")
def read_root():
return {
"status": "scraper is running in background",
"timestamp": datetime.utcnow().isoformat() + "Z"
}