mirror of
https://github.com/ChenKaiLiuG/find_your_own_fxxking_problem.git
synced 2026-06-17 16:54:24 +00:00
Create run_print_4html.py
This commit is contained in:
27
runprint4html.py
Normal file
27
runprint4html.py
Normal 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()
|
||||
Reference in New Issue
Block a user