Logo Pastebin.fr
Pastebin

Retrouvez, créez et partagez vos snippets en temps réel.

aaaaaaa

from fastapi import FastAPI, Request, HTTPException
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates

import json
from ordinateur import Ordinateur

app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
ordi1 = Ordinateur()

@app.get("/ordi1", response_class=HTMLResponse)
async def read_item(request: Request):
    return templates.TemplateResponse(
        request=request, name="ordi.html", context={"ordi": ordi1}
    )
@app.post("/endpoint")

async def receive_info(request: Request):
    # lire le body brut
    body = await request.body()
    print(body)

    # Parse le json
    try:
        data = json.loads(body)
    except json.JSONDecodeEror :
        raise HTTPException(status_code=400, detail="Invalid JSON") 

    # DEBUG

    print("Infos reçus :", data)
    #ordi1 = Ordinateur()
    hardware = data.get('HARDWARE', {})
    software = data.get('SOFTWARE', {})
    ordi1.mb_serial = hardware.get('mb_serial', "N/A")
    ordi1.hostname = hardware.get('hostname', "N/A")
    ordi1.cpu = hardware.get('cpu', "N/A")
    ordi1.cpu_id = hardware.get('cpu_id', "N/A")
    ordi1.cpu_cores_number = hardware.get('cpu_cores_number', "N/A")
    ordi1.cpu_threads_number = hardware.get('cpu_threads_number', "N/A")
    ordi1.cpu_frequency_min = hardware.get('cpu_frequency_min', "N/A")
    ordi1.cpu_frequency_cur = hardware.get('cpu_frequency_cur', "N/A")
    ordi1.cpu_frequency_max = hardware.get('cpu_frequency_max', "N/A")
    ordi1.gpu_model = hardware.get('gpu_model', "N/A")
    ordi1.ram_slots_number = hardware.get('ram_slots_number', "N/A")
    ordi1.ram_gen = hardware.get('ram_gen', "N/A")

    ordi1.os = software.get('os', "N/A")
    ordi1.arch = software.get('arch', "N/A")
    ordi1.desktop = software.get('desktop', "N/A")
    ordi1.kernel = software.get('kernel', "N/A")
    # ordi1.mb_serial = data['HARDWARE']['mb_serial']
    # ordi1.hostname = data['HARDWARE']['hostname']
    # ordi1.cpu = data['HARDWARE']['cpu']
    # ordi1.cpu_id = data['HARDWARE']['cpu_id']
    # ordi1.cpu_cores_number = data['HARDWARE']['cpu_cores_number']
    # ordi1.cpu_threads_number = data['HARDWARE']['cpu_threads_number']
    # ordi1.cpu_frequency_min = data['HARDWARE']['cpu_frequency_min']
    # ordi1.cpu_frequency_cur = data['HARDWARE']['cpu_frequency_cur']
    # ordi1.cpu_frequency_max = data['HARDWARE']['cpu_frequency_max']
    # ordi1.gpu_model = data['HARDWARE']['gpu_model']
    # ordi1.ram_slots_number = data['HARDWARE']['ram_slots_number']
    # ordi1.ram_gen = data['HARDWARE']['ram_gen']
    # ordi1.os = data['SOFTWARE']['os']
    # ordi1.arch = data['SOFTWARE']['arch']
    # ordi1.desktop = data['SOFTWARE']['desktop']
    # ordi1.kernel = data['SOFTWARE']['kernel']

    print(f"Le serial demb est {ordi1.mb_serial}")

    return({"status ": "ok"})


Créé il y a 3 jours.

Rechercher un Pastebin

Aucun paste trouvé.