From ff88d46d0b8ce1d6b47a9639371bdcb59e999953 Mon Sep 17 00:00:00 2001 From: George Date: Tue, 28 Jan 2025 21:05:38 +0200 Subject: [PATCH 1/2] Update ChessBoard.py Coordinate Labels: Displays row numbers (1-8) and column letters (A-H) around the board. Dynamic Piece Placement: Pieces (e.g., rooks and pawns) are placed using Unicode chess symbols. Square Highlighting: Allows highlighting specific squares (e.g., valid moves or selected positions). --- Chess Board/ChessBoard.py | 67 ++++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 12 deletions(-) diff --git a/Chess Board/ChessBoard.py b/Chess Board/ChessBoard.py index 122080a..2c64f25 100644 --- a/Chess Board/ChessBoard.py +++ b/Chess Board/ChessBoard.py @@ -1,20 +1,63 @@ import matplotlib.pyplot as plt import numpy as np -from matplotlib.colors import LogNorm +from matplotlib.patches import Rectangle -dx, dy = 0.015, 0.05 -# numpy.arange returns evenly spaced values within a given interval -x = np.arange(-4.0, 4.0, dx) # Corrected -04.0 to -4.0 -y = np.arange(-4.0, 4.0, dy) # Corrected -04.0 to -4.0 -# returns coordinate matrices from coordinate vectors -X, Y = np.meshgrid(x, y) +# Chess symbols for pieces (Unicode) +chess_pieces = { + "rook_white": "\u2656", + "rook_black": "\u265C", + "pawn_white": "\u2659", + "pawn_black": "\u265F", +} -extent = np.min(x), np.max(x), np.min(y), np.max(y) +# Initial piece positions for demonstration +initial_pieces = [ + (0, 0, chess_pieces["rook_black"]), + (0, 7, chess_pieces["rook_black"]), + (7, 0, chess_pieces["rook_white"]), + (7, 7, chess_pieces["rook_white"]), + (1, 0, chess_pieces["pawn_black"]), + (1, 7, chess_pieces["pawn_black"]), + (6, 0, chess_pieces["pawn_white"]), + (6, 7, chess_pieces["pawn_white"]), +] -Z1 = np.add.outer(range(8), range(8)) % 2 +# Function to draw the chessboard +def draw_chessboard(highlight_squares=None): + board_size = 8 + chessboard = np.add.outer(range(board_size), range(board_size)) % 2 -plt.imshow(Z1, cmap="binary_r", interpolation="nearest", extent=extent, alpha=1) + fig, ax = plt.subplots(figsize=(8, 8)) + ax.imshow(chessboard, cmap="cividis", interpolation="nearest") -plt.title("Chess Board", fontweight="bold") + # Remove axes for a cleaner look + ax.set_xticks([]) + ax.set_yticks([]) -plt.show() + # Add grid lines to separate the squares + for i in range(board_size + 1): + ax.axhline(i - 0.5, color="black", linewidth=1, alpha=0.7) + ax.axvline(i - 0.5, color="black", linewidth=1, alpha=0.7) + + # Highlight specific squares + if highlight_squares: + for (row, col) in highlight_squares: + ax.add_patch(Rectangle((col - 0.5, row - 0.5), 1, 1, color="yellow", alpha=0.4)) + + # Add chess pieces + for row, col, piece in initial_pieces: + ax.text(col, row, piece, fontsize=28, ha="center", va="center", color="black" if (row + col) % 2 == 0 else "white") + + # Add coordinate labels + for i in range(board_size): + ax.text(-0.8, i, str(8 - i), fontsize=12, va="center") # Row labels + ax.text(i, 8 - 0.3, chr(65 + i), fontsize=12, ha="center") # Column labels + + # Title + ax.set_title("Chess Board", fontweight="bold", fontsize=16) + + plt.show() + +# Highlight squares (optional demo) +highlight = [(0, 0), (7, 7), (3, 3)] # Example of squares to highlight +draw_chessboard(highlight_squares=highlight) From f3f077261332fdeb3bbd715594c80e816e466c9e Mon Sep 17 00:00:00 2001 From: George Date: Mon, 17 Feb 2025 21:38:30 +0200 Subject: [PATCH 2/2] Fixes Implemented Properly handled form POST requests Created a /cloned_sites/ directory for saved pages Fixed JavaScript to properly submit the form Handled errors gracefully --- Website Cloner/index.html | 58 +++++++++++++++------------------ Website Cloner/server.py | 67 +++++++++++++++++++++++++-------------- 2 files changed, 69 insertions(+), 56 deletions(-) diff --git a/Website Cloner/index.html b/Website Cloner/index.html index 26c2f4e..357d9e7 100644 --- a/Website Cloner/index.html +++ b/Website Cloner/index.html @@ -1,40 +1,32 @@ - PROXY SERVER - - - - + PROXY SERVER + + + + -
-
-
-
-
- - - - - -
- -
- -
-
-
-
-
- - +
+
+
+
+
+ + + + + +
+
+ +
+
+
+
+
diff --git a/Website Cloner/server.py b/Website Cloner/server.py index 3816e4b..446f8bc 100644 --- a/Website Cloner/server.py +++ b/Website Cloner/server.py @@ -8,31 +8,52 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler): def do_GET(self): if self.path == "/": self.path = "index.html" - return http.server.SimpleHTTPRequestHandler.do_GET(self) + try: + return http.server.SimpleHTTPRequestHandler.do_GET(self) + except FileNotFoundError: + self.send_error(404, "File not found") + def do_POST(self): - form = cgi.FieldStorage( - fp=self.rfile, - headers=self.headers, - environ={ - 'REQUEST_METHOD': 'POST', - 'CONTENT_TYPE': self.headers['Content-Type'], - }) - url = form.getvalue('submitButton') - urlN = 'https://' + str(url) +'/' - isdir = os.path.isdir(url) - if not isdir: - kwargs = {'project_name': url} - save_webpage( - url=urlN, - project_folder='./', - **kwargs - ) - path = url + "/" + url + "/index.html" + content_length = int(self.headers.get('Content-Length', 0)) + post_data = self.rfile.read(content_length).decode("utf-8") + + # Parse the URL from the form submission + form = cgi.parse_qs(post_data) + url = form.get("submitButton", [""])[0] + + if not url: + self.send_error(400, "Bad Request: URL is missing") + return + + urlN = "https://" + url.strip("/") + project_folder = os.path.join('./cloned_sites', url.replace("https://", "").replace("http://", "")) + + if not os.path.isdir(project_folder): + os.makedirs(project_folder, exist_ok=True) + try: + save_webpage( + url=urlN, + project_folder=project_folder, + project_name=url.replace("https://", "").replace("http://", "") + ) + except Exception as e: + self.send_error(500, f"Error cloning website: {e}") + return + + path = os.path.join(project_folder, "index.html") + if not os.path.isfile(path): + self.send_error(404, "Cloned page not found") + return + self.send_response(301) - self.send_header('Location', path) + self.send_header("Location", "/" + path) self.end_headers() - return http.server.SimpleHTTPRequestHandler.do_GET(self) + PORT = 7000 -s = socketserver.TCPServer(("127.0.0.1", PORT), RequestHandler) -s.serve_forever() \ No newline at end of file +os.chdir(os.path.dirname(os.path.abspath(__file__))) + +with socketserver.TCPServer(("127.0.0.1", PORT), RequestHandler) as s: + s.allow_reuse_address = True + print(f"Server running on http://127.0.0.1:{PORT}") + s.serve_forever()