v1.1
This commit is contained in:
@@ -63,6 +63,22 @@ class CustomHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
|
||||
if parsed_path.path == '/' or parsed_path.path == '/index.html':
|
||||
self.path = '/index.html'
|
||||
|
||||
if parsed_path.path == '/committees.html':
|
||||
self.path = '/committees.html'
|
||||
|
||||
if parsed_path.path.startswith('/committees/'):
|
||||
file_path = self.path[1:] # убираем первый слеш
|
||||
if os.path.exists(file_path):
|
||||
self.send_response(200)
|
||||
if file_path.endswith('.json'):
|
||||
self.send_header('Content-Type', 'application/json; charset=utf-8')
|
||||
self.end_headers()
|
||||
with open(file_path, 'rb') as f:
|
||||
self.wfile.write(f.read())
|
||||
else:
|
||||
self.send_error(404, 'File not found')
|
||||
return
|
||||
|
||||
if self.path.endswith('.html'):
|
||||
self.send_response(200)
|
||||
self.send_header('Content-Type', 'text/html; charset=utf-8')
|
||||
@@ -132,6 +148,31 @@ class CustomHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
|
||||
self.wfile.write(response.encode('utf-8'))
|
||||
return
|
||||
|
||||
# Сохранение комитетов
|
||||
if parsed_path.path.startswith('/save_committees/'):
|
||||
filename = parsed_path.path.replace('/save_committees/', '')
|
||||
content_length = int(self.headers.get('Content-Length', 0))
|
||||
post_data = self.rfile.read(content_length)
|
||||
|
||||
try:
|
||||
data = json.loads(post_data.decode('utf-8'))
|
||||
file_path = f'committees/{filename}'
|
||||
with open(file_path, 'w', encoding='utf-8') as f:
|
||||
json.dump(data, f, ensure_ascii=False, indent=2)
|
||||
|
||||
self.send_response(200)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
response = json.dumps({'success': True, 'message': 'Данные комитетов сохранены'})
|
||||
self.wfile.write(response.encode('utf-8'))
|
||||
except Exception as e:
|
||||
self.send_response(500)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
response = json.dumps({'success': False, 'message': str(e)})
|
||||
self.wfile.write(response.encode('utf-8'))
|
||||
return
|
||||
|
||||
self.send_response(404)
|
||||
self.end_headers()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user