Move to directory /run

This commit is contained in:
ChenKaiLiuG
2025-04-02 21:07:56 +08:00
committed by GitHub
parent e3924c0c50
commit 8ac1a58e2c

27
run/runprint4html.py Normal file
View File

@@ -0,0 +1,27 @@
from http.server import SimpleHTTPRequestHandler, HTTPServer
import os
class MyHandler(SimpleHTTPRequestHandler):
def do_GET(self):
if self.path == '/get_file_content':
filename = '找找自己問題.txt'
if os.path.exists(filename):
with open(filename, 'r', encoding='utf-8') as f:
content = f.read()
self.send_response(200)
self.send_header('Content-type', 'text/plain; charset=utf-8')
self.end_headers()
self.wfile.write(content.encode('utf-8'))
else:
self.send_response(404)
self.send_header('Content-type', 'text/plain; charset=utf-8')
self.end_headers()
self.wfile.write(b'File not found.')
else:
super().do_GET()
if __name__ == '__main__':
port = 8000
httpd = HTTPServer(('localhost', port), MyHandler)
print(f"Serving on port {port}")
httpd.serve_forever()