main.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from http.server import HTTPServer, BaseHTTPRequestHandler
  2. import requests
  3. import re
  4. from datetime import datetime
  5. class HttpGetHandler(BaseHTTPRequestHandler):
  6. def do_GET(self):
  7. try:
  8. if self.path.endswith("/"):
  9. self.send_response(200)
  10. self.send_header("Content-type", "text/html")
  11. self.end_headers()
  12. http_text = """<html><head><meta charset='utf-8'>
  13. <title>Simple HTTP Server</title></head>
  14. <body>Ok<br>
  15. <a href="http://localhost:8000/info">Info</a></body><html>
  16. <a href="http://localhost:8000/Status">Status</a></body><html>"""
  17. self.wfile.write(http_text.encode())
  18. if self.path.endswith("/info"):
  19. self.send_response(200)
  20. self.send_header("Content-type", "text/html")
  21. self.end_headers()
  22. http_text = """<html><head><meta charset='utf-8'>
  23. <title>Info</title></head>
  24. <body>Info<br>
  25. <body>Opanasenko Kirill Olegovich<br>
  26. <body>gr-704<br>
  27. <a href="http://localhost:8000/">Ok</a></body><html>
  28. <a href="http://localhost:8000/Status">Status</a></body><html>"""
  29. self.wfile.write(http_text.encode())
  30. except IOError:
  31. self.send_error(400,f"File not found{self.path}")
  32. def main(server_class=HTTPServer,handler_class=HttpGetHandler):
  33. server_address = ('localhost',8000)
  34. httpd = server_class(server_address,handler_class)
  35. try:
  36. print("Start server")
  37. httpd.serve_forever()
  38. except KeyboardInterrupt:
  39. httpd.server_close()
  40. print("Kill server")
  41. if __name__ == '__main__':
  42. main()