TimeStampBuddy / app.py
Mihaiii's picture
Update app.py
115c7b7 verified
raw
history blame
1.21 kB
import subprocess
import logging
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
app = FastAPI()
subprocess.Popen(["python3", "TimeStampBuddy/cron_processor.py"])
@app.get("/", response_class=HTMLResponse)
def welcome():
return """
<div>
<h1>Hello!</h1>
<p>This service powers the <a href="https://x.com/TimeStampBuddy" target="_blank" rel="noopener noreferrer">@TimeStampBuddy</a>'s activity on Twitter.</p>
<p>For more details, visit
<a href="https://github.com/Mihaiii/TimeStampBuddy" target="_blank" rel="noopener noreferrer">GitHub Repository</a>.
</p>
</div>
"""
class LogLevelRequest(BaseModel):
level: str
@app.post("/set_log_level")
async def set_log_level(request: LogLevelRequest):
try:
logger = logging.getLogger()
level = request.level.upper()
if level in ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']:
logger.setLevel(level)
return {"message": f"Log level changed to {level}"}
raise HTTPException(status_code=400, detail="Invalid log level")
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))