All gists matching topic http-server

timmy / 磁碟使用量查詢 API

0 Kedvelések
0 forkok
1 fájlok
Utoljára aktív 10 months ago
這段程式碼建立了一個簡單的 HTTP 伺服器,透過 /disk-usage API 端點提供磁碟空間使用狀況的查詢功能。使用者可以透過 GET 請求並指定 path 參數來獲取該目錄的總空間、已使用空間、可用空間及使用率,適用於系統監控或遠端管理工具。
1 import json
2 from http.server import BaseHTTPRequestHandler, HTTPServer
3 from urllib.parse import urlparse, parse_qs
4 import shutil
5
6
7 class DiskUsage:
8 def __init__(self, path="/"):
9 self.path = path
Újabb Régebbi