Blog/backend/backend.py

62 lines
2.8 KiB
Python
Raw Permalink Normal View History

2024-01-16 11:42:01 +00:00
import http.server
import socketserver
import subprocess
from urllib.parse import urlparse, parse_qs
class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
parsed_path = urlparse(self.path)
query = parse_qs(parsed_path.query)
print(query)
if 'command' in query and 'args' in query:
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(bytes(f"command: {query['command']}, args: {query['args']}", "utf-8"))
else:
self.send_response(400)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(bytes("Bad request", "utf-8"))
PORT = 2281
Handler = MyHttpRequestHandler
def compile_and_deploy_contract():
2024-01-16 11:54:54 +00:00
password = 'one'
2024-01-16 11:42:01 +00:00
# User
user_compile_command = "neo-go contract compile -i User/user.go -c User/user.yml -m User/user.json"
subprocess.run(user_compile_command, shell=True, check=True)
user_deploy_command = "neo-go contract deploy -i User/user.nef -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 -m User/user.json"
subprocess.run(user_deploy_command, shell=True, check=True)
2024-01-16 11:54:54 +00:00
result_user = subprocess.check_output(password, shell=True, text=True).stdout[-40:]
print(result_user)
2024-01-16 11:42:01 +00:00
# Post
post_compile_command = "neo-go contract compile -i Post/post_contract.go -c Post/post_contract.yml -m Post/post_contract.json"
subprocess.run(post_compile_command, shell=True, check=True)
post_deploy_command = "neo-go contract deploy -i Post/post_contract.nef -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 -m Post/post_contract.json"
subprocess.run(post_deploy_command, shell=True, check=True)
2024-01-16 11:54:54 +00:00
result_post = subprocess.check_output(password, shell=True, text=True).stdout[-40:]
print(result_post)
2024-01-16 11:42:01 +00:00
# Comment
comment_compile_command = "neo-go contract compile -i Comment/comment.go -c Comment/comment.yml -m Comment/comment.json"
subprocess.run(comment_compile_command, shell=True, check=True)
comment_deploy_command = "neo-go contract deploy -i Comment/comment.nef -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 -m Comment/comment.json"
subprocess.run(comment_deploy_command, shell=True, check=True)
2024-01-16 11:54:54 +00:00
result_comment = subprocess.check_output(password, shell=True, text=True).stdout[-40:]
print(result_comment)
2024-01-16 11:42:01 +00:00
if __name__ == "__main__":
compile_and_deploy_contract()
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("Сервер запущен на порту", PORT)
httpd.serve_forever()
httpd.server_close()