| 
					
				 | 
			
			
				@@ -0,0 +1,53 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+from http.server import HTTPServer, BaseHTTPRequestHandler 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import requests 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import datetime 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+class HttpGetHandler(BaseHTTPRequestHandler): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    def do_GET(self): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if self.path.endswith("/"): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                self.send_response(200) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                self.send_header("Content-type", "text/html") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                self.end_headers() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                http_text = """ <html><head><meta charset= 'utf-8'> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                <title>Простой HTTP-сервер.</title></head> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                <body>Это главная страница.</body></html> """ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                self.wfile.write(http_text.encode()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if self.path.endswith("/info"): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                self.send_response(200) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                self.send_header("Content-type", "text/html") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                self.end_headers() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                res = requests.get('https://api.ipify.org/') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                http_text = f"<!doctype html><html><head><meta charset=utf-8>" \ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                   f"<title>http-server/info</title></head>" \ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                   f"<body>Ваш адресс {res.text}.<br>" \ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                   f"<body>Кондратюк Андрей Андреевич<br>" \ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                   f"Время на сервере {str(datetime.datetime.now())}" \ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                   f"<p>гр 701(3)</p>" \ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                   f"</body></html>" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                self.wfile.write(http_text.encode(encoding='utf-8')) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        except IOError: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            self.send_error(400, f"File 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("Запускаем сервер!") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        httpd.serve_forever() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    except KeyboardInterrupt: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        httpd.server_close() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        print("Сервер остановлен!") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+if __name__ == '__main__': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    main() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 |