From e2593c900527b861741c26506d2c366772fb72ad Mon Sep 17 00:00:00 2001 From: Sara <sarasdj@stud.ntnu.no> Date: Tue, 23 Apr 2024 10:57:55 +0200 Subject: [PATCH] add: comments and docstrings to get_lake_relation.py --- server/map_handler/get_lake_relation.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/server/map_handler/get_lake_relation.py b/server/map_handler/get_lake_relation.py index edb59ebb..2b820eb0 100644 --- a/server/map_handler/get_lake_relation.py +++ b/server/map_handler/get_lake_relation.py @@ -2,7 +2,15 @@ from server.consts import LAKE_RELATIONS_PATH # Writes contents of a lake json file to the response -def get_map_data(self, file_name, measurement: bool): +def get_map_data(self, file_name: str, measurement: bool): + """ + Reads a map file and writes its contents to the response object. + + Parameters: + self (BaseHTTPRequestHandler): A instance of a BaseHTTPRequestHandler + file_name (str): The name of the requested file/lake + measurement (bool): Whether the file is of type _measurements.json or _div.json + """ try: if measurement: file_type = "_measurements.json" @@ -13,6 +21,7 @@ def get_map_data(self, file_name, measurement: bool): with open(LAKE_RELATIONS_PATH + file_name + file_type, "r") as file: data = file.read() + # Set HTTP headers self.send_response(200) self.send_header("Content-type", "application/json") self.end_headers() @@ -23,7 +32,7 @@ def get_map_data(self, file_name, measurement: bool): self.send_response(404) self.send_header("Content-type", "application/json") self.end_headers() - except Exception as e: + except Exception: self.send_response(500) self.send_header("Content-type", "application/json") self.end_headers() -- GitLab