This repository has been archived on 2026-02-12. You can view files and clone it, but cannot push or open issues or pull requests.
old-grabber/app.py
2026-01-16 14:58:56 +01:00

34 lines
779 B
Python

from fastapi import FastAPI, Request, HTTPException
import json
from grabber import Grabber
app = FastAPI()
ordi1 = Grabber()
@app.post("/endpoint")
async def receive_info(request: Request):
# Lire le body brut
body = await request.body()
print(body)
# Parser le JSON
try:
data = json.loads(body)
except json.JSONDecodeError:
raise HTTPException(status_code=400, detail="Invalid JSON")
# Debug
print("Data grabbed :", data)
ordi1.hostname = data['HARDWARE']['hostname']
ordi1.mb_serial = data['HARDWARE']['mb_serial']
print(f"Hostname is {ordi1.hostname}")
print(f"Motherboard serial is {ordi1.mb_serial}")
return {"status": "ok"}
@app.get("/ordi1")
async def get_ordi1_info():
return ordi1