aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/docs
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2023-07-06 13:43:48 +0800
committerGitHub <noreply@github.com>2023-07-06 13:43:48 +0800
commit48f9f8900474f7bed460b0516afc752d792ed1be (patch)
tree7ee5b33b55345e9eff1a65041dfe61938d4341d1 /docs
parent32b4ae87ec729b394fd9167c5bfb977d11f4d5f6 (diff)
downloadHydroRoll-48f9f8900474f7bed460b0516afc752d792ed1be.tar.gz
HydroRoll-48f9f8900474f7bed460b0516afc752d792ed1be.zip
Create roots.py
Diffstat (limited to 'docs')
-rw-r--r--docs/api/roots.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/docs/api/roots.py b/docs/api/roots.py
new file mode 100644
index 0000000..eb126d7
--- /dev/null
+++ b/docs/api/roots.py
@@ -0,0 +1,23 @@
+import json
+import random
+from http.server import BaseHTTPRequestHandler
+from os.path import dirname, abspath, join
+
+dir = dirname(abspath(__file__))
+
+class handler(BaseHTTPRequestHandler):
+ def do_GET(self):
+ self.send_response(200)
+ self.send_header('Content-type', 'application/json')
+ self.end_headers()
+
+ with open(join(dir, '..', 'data', 'file.txt'), 'r', encoding='utf-8') as file:
+ lines = file.readlines()
+ random_line = random.choice(lines)
+ response = {
+ 'line': random_line.strip()
+ }
+ response_json = json.dumps(response, ensure_ascii=False)
+
+ self.wfile.write(response_json.encode('utf-8'))
+ return