diff mail/file-count/file_count.py @ 326:5b88b38f2471

huge reorg, reog toplevel functions in preparation of a ui with nice task lists
author drewp@bigasterisk.com
date Mon, 20 Jan 2025 21:55:08 -0800
parents templates/file-count/file_count.py@67fb7b27bfea
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mail/file-count/file_count.py	Mon Jan 20 21:55:08 2025 -0800
@@ -0,0 +1,20 @@
+import http.server
+import socketserver
+import os
+import sys
+
+interface, port, dir, metric_name = sys.argv[1:]
+
+
+class Web(http.server.SimpleHTTPRequestHandler):
+
+    def do_GET(self):
+        files_count = len(os.listdir(dir))
+        self.send_response(200)
+        self.send_header('Content-type', 'text/plain')
+        self.end_headers()
+        self.wfile.write(f'{metric_name} {files_count}'.encode())
+
+
+with socketserver.TCPServer((interface, int(port)), Web) as httpd:
+    httpd.serve_forever()