|
@@ -1,6 +1,10 @@
|
|
|
+import datetime
|
|
|
from http.server import HTTPServer, BaseHTTPRequestHandler
|
|
|
|
|
|
# asd
|
|
|
+import requests
|
|
|
+
|
|
|
+
|
|
|
class HttpGethandler(BaseHTTPRequestHandler):
|
|
|
def do_GET(self):
|
|
|
try:
|
|
@@ -10,11 +14,11 @@ class HttpGethandler(BaseHTTPRequestHandler):
|
|
|
self.send_header("Content-type", "text/html")
|
|
|
self.end_headers()
|
|
|
|
|
|
- http_text = """<html><head><meta charset='utf-8'
|
|
|
- <title>Есть</title></head>
|
|
|
- <body>Работает.</body></html>"""
|
|
|
+ html = f"<html><head><meta charset='utf-8'><title>Damned HTTP-Server</title></head>" \
|
|
|
+ f"<body>It`s Damned HTTP-Server working probably" \
|
|
|
+ f"</body></html>"
|
|
|
|
|
|
- self.wfile.write(http_text.encode())
|
|
|
+ self.wfile.write(html.encode())
|
|
|
|
|
|
if self.path.endswith("/info"):
|
|
|
self.send_response(200)
|
|
@@ -22,25 +26,38 @@ class HttpGethandler(BaseHTTPRequestHandler):
|
|
|
self.send_header("Content-type", "text/html")
|
|
|
self.end_headers()
|
|
|
|
|
|
- http_text = """<html><head><meta charset='utf-8'
|
|
|
- <title>Трифонов А.Л. 701(3)</title></head></html>"""
|
|
|
+ html = f"<html><head><meta charset='utf-8'><title>Damned HTTP-Server</title></head>" \
|
|
|
+ f"<body>Trifonov Adam (701)3" \
|
|
|
+ f"</body></html>"
|
|
|
+
|
|
|
+ self.wfile.write(html.encode())
|
|
|
+
|
|
|
+ if self.path.endswith("status"):
|
|
|
+ self.send_response(200)
|
|
|
+ self.send_header("Content-type", "text/html")
|
|
|
+ self.end_headers()
|
|
|
+ get = requests.get('https://api.ipify.org/')
|
|
|
|
|
|
- self.wfile.write(http_text.encode())
|
|
|
+ html = f"<html><head><meta charset='utf-8'><title>Damned HTTP-Server</title></head>" \
|
|
|
+ f"<body>Your address on the Damned HTTP-Server: {get.text}<br>" \
|
|
|
+ f"Time on the Damned HTTP-Server: {str(datetime.datetime.now())}" \
|
|
|
+ f"</body></html>"
|
|
|
+ self.wfile.write(html.encode())
|
|
|
|
|
|
except IOError:
|
|
|
- self.send_error(400, f"Не нашел{self.path}")
|
|
|
+ self.send_error(400, f'Damned HTTP-Server not found{self.path}')
|
|
|
|
|
|
|
|
|
def main(server_class=HTTPServer, handler_class=HttpGethandler):
|
|
|
server_address = ('localhost', 8000)
|
|
|
httpd = server_class(server_address, handler_class)
|
|
|
try:
|
|
|
- print("Поехали!")
|
|
|
+ print("Damned HTTP-Server started")
|
|
|
httpd.serve_forever()
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
httpd.server_close()
|
|
|
- print("Стоять!")
|
|
|
+ print("Damned HTTP-Server stopped")
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|