json vue html

This commit is contained in:
Tenzing Kandang 2026-01-16 17:00:18 +01:00
parent 1d6cb48e47
commit 8fdcd6c327
3 changed files with 50 additions and 5 deletions

47
app.py
View File

@ -1,8 +1,27 @@
from fastapi import FastAPI, Request, HTTPException from fastapi import FastAPI, Request, HTTPException
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
import json import json
from ordinateur import ordinateur from ordinateur import ordinateur
app = FastAPI() app = FastAPI()
ordi1 = ordinateur()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
@app.get("/ordi1", response_class=HTMLResponse)
async def get_ordi1_info(request: Request):
return templates.TemplateResponse(
request=request, name="item.html", context={"ordi": ordi1}
)
@app.post("/endpoint") @app.post("/endpoint")
async def receive_info(request: Request): async def receive_info(request: Request):
# Lire le body brut # Lire le body brut
@ -16,10 +35,8 @@ async def receive_info(request: Request):
except json.JSONDecodeError: except json.JSONDecodeError:
raise HTTPException(status_code=400, detail="Invalid JSON") raise HTTPException(status_code=400, detail="Invalid JSON")
# Debug # Debug
print("Infos reçues :", data) print("Infos reçues :", data)
ordi1 = ordinateur()
ordi1.mb_serial = data['HARDWARE']['mb_serial'] ordi1.mb_serial = data['HARDWARE']['mb_serial']
ordi1.hostname = data['HARDWARE']['hostname'] ordi1.hostname = data['HARDWARE']['hostname']
ordi1.cpu = data['HARDWARE']['cpu'] ordi1.cpu = data['HARDWARE']['cpu']
@ -27,9 +44,33 @@ async def receive_info(request: Request):
ordi1.memory_mb = data['HARDWARE']['memory_mb'] ordi1.memory_mb = data['HARDWARE']['memory_mb']
ordi1.ram_size = data['HARDWARE']['ram_size'] ordi1.ram_size = data['HARDWARE']['ram_size']
ordi1.ram_gen = data['HARDWARE']['ram_gen'] ordi1.ram_gen = data['HARDWARE']['ram_gen']
ordi1.sizes = data['HARWARE']['sizes'] ordi1.sizes = data['HARDWARE']['sizes']
ordi1.cpu_freq_min = data['HARDWARE']['cpu_freq_min']
ordi1.cpu_freq_cur = data['HARDWARE']['cpu_freq_cur']
ordi1.cpu_freq_max = data['HARDWARE']['cpu_freq_max']
ordi1.gpu_model = data['HARDWARE']['gpu_model']
ordi1.chassis_serial = data['HARDWARE']['chassis_serial']
ordi1.cpu_cores_nb = data['HARDWARE']['cpu_cores_nb']
ordi1.cpu_threads_nb = data['HARDWARE']['cpu_threads_nb']
ordi1.ram_number = data['HARDWARE']['ram_number']
ordi1.ram_slots_nb = data['HARDWARE']['ram_slots_nb']
ordi1.os = data['SOFTWARE']['os']
ordi1.arch = data['SOFTWARE']['arch']
ordi1.desktop = data['SOFTWARE']['desktop']
ordi1.wm = data['SOFTWARE']['wm']
ordi1.kernel = data['SOFTWARE']['kernel']
ordi1.mac_adresse = data['SOFTWARE']['mac_adresse']
#Test
print(f"Le serial de la mb est {ordi1.mb_serial}") print(f"Le serial de la mb est {ordi1.mb_serial}")
print(f"Hostname est {ordi1.hostname}") print(f"Hostname est {ordi1.hostname}")
print(f"Your cpu is {ordi1.cpu}") print(f"Your cpu is {ordi1.cpu}")
print(f"Le id de ce cpu est {ordi1.cpu_id}") print(f"Le id de ce cpu est {ordi1.cpu_id}")
print(f"le memory en megabytes {ordi1.memory_mb}")
print(f"Voici numéro de ram {ordi1.ram_number}")
return ({"status": "ok"}) return ({"status": "ok"})
#@app.get("/ordi1")
#async def get_ordi1_info():
# return ordi1

View File

@ -37,7 +37,7 @@ ARCH=$(uname -m)
DESKTOP=$XDG_CURRENT_DESKTOP DESKTOP=$XDG_CURRENT_DESKTOP
WM=$XDG_SESSION_TYPE WM=$XDG_SESSION_TYPE
KERNEL=$(uname -r) KERNEL=$(uname -r)
MAC_ADRESSE=$(ip link | awk '/ether/ {print $2; exit}')
##########SIMPLELOCAL#################### ##########SIMPLELOCAL####################
# Construire le JSON # Construire le JSON
@ -64,6 +64,7 @@ json_data=$(jq -n \
--arg desktop "$DESKTOP" \ --arg desktop "$DESKTOP" \
--arg wm "$WM" \ --arg wm "$WM" \
--arg kernel "$KERNEL" \ --arg kernel "$KERNEL" \
--arg mac_adresse "$MAC_ADRESSE" \
'{ '{
HARDWARE: { HARDWARE: {
hostname:$host, hostname:$host,
@ -89,7 +90,8 @@ json_data=$(jq -n \
arch:$arch, arch:$arch,
desktop:$desktop, desktop:$desktop,
wm:$wm, wm:$wm,
kernel:$kernel kernel:$kernel,
mac_adresse:$mac_adresse
} }
}') }')
@ -218,6 +220,7 @@ software() {
echo "DESKTOP=$XDG_CURRENT_DESKTOP" echo "DESKTOP=$XDG_CURRENT_DESKTOP"
echo "WM=$XDG_SESSION_TYPE" echo "WM=$XDG_SESSION_TYPE"
echo "KERNEL=$(uname -r)" echo "KERNEL=$(uname -r)"
echo "MAC_ADRESSE=$MAC_ADRESSE"
} >>$SUM } >>$SUM
hardware hardware

View File

@ -24,6 +24,7 @@ class ordinateur():
desktop = "" desktop = ""
wm = "" wm = ""
kernel = "" kernel = ""
mac_adresse = ""
''' '''