From 77f78b0ec466b5e3561013a719312062d3fbc2e2 Mon Sep 17 00:00:00 2001 From: spacekiddo Date: Tue, 25 Jun 2024 18:05:30 +0600 Subject: [PATCH 1/2] Remove repeating if...else statements --- start.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/start.py b/start.py index d753346..9236413 100644 --- a/start.py +++ b/start.py @@ -80,7 +80,6 @@ # Store the initial coordinates and initialize lists to store the coordinates for each step initial_latitude = latitude initial_longitude = longitude -step_coordinates = [] # Initialize variables to store coordinates and counts coordinates = [] @@ -114,21 +113,15 @@ # Printing city and country by coordinates print_city_by_geo(latitude, longitude) -# Perform steps according to the pattern -for i, steps in enumerate(pattern): - if i == 0: - direction = "starting" - elif i % 4 == 1: - direction = "west" - elif i % 4 == 2: - direction = "south" - elif i % 4 == 3: - direction = "east" - else: - direction = "north" +# Calculate steps according to the pattern and store it in the step_coordinates var +directions = ("north", "west", "south", "east") +direction = "starting" +step_coordinates = [] +for i, steps in enumerate(pattern, start=1): for _ in range(steps): latitude, longitude = calculate_coordinates(latitude, longitude, direction, 0.6) # 600 meters in kilometers step_coordinates.append((latitude, longitude)) + direction = directions[i % 4] # Print number of steps print_len_steps(len(step_coordinates), meters) From af509d6ba0e6151c71efe5c1f8ec8362a0d3e5ec Mon Sep 17 00:00:00 2001 From: spacekiddo Date: Tue, 25 Jun 2024 18:10:00 +0600 Subject: [PATCH 2/2] Remove some unused variables, correct typos and imports It seems like some variables wasn't used since the first commits, so I removed them. Additionally, changed relative imports to absolute and corrected typos in comment and function name. --- backend/banners.py | 4 ++-- backend/combine_data.py | 4 ++-- start.py | 18 +++--------------- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/backend/banners.py b/backend/banners.py index 42ddf0e..1264df6 100644 --- a/backend/banners.py +++ b/backend/banners.py @@ -1,4 +1,4 @@ -from .functions import get_location_details +from backend.functions import get_location_details # Banner banner = """ @@ -23,7 +23,7 @@ """ -def print_geo_coordinater(lat, lon): +def print_geo_coordinates(lat, lon): print("[ * ] Harvesting information based on the next coordinates:") print("\t[ * * ] Latitude: ", lat) print("\t[ * * ] Longitude:", lon) diff --git a/backend/combine_data.py b/backend/combine_data.py index 1fe762b..4a942a3 100644 --- a/backend/combine_data.py +++ b/backend/combine_data.py @@ -1,5 +1,5 @@ -from .functions import combine_json_files -from .json_into_html import generate_html_from_json +from backend.functions import combine_json_files +from backend.json_into_html import generate_html_from_json def combine_data(report_json_directory="./reports-json/", report_html_directory="./reports-html/"): diff --git a/start.py b/start.py index 9236413..def3315 100644 --- a/start.py +++ b/start.py @@ -16,7 +16,7 @@ print_combined_data, print_current_step, print_files_stored, - print_geo_coordinater, + print_geo_coordinates, print_len_steps, print_start_harvesting, print_successfully, @@ -77,18 +77,6 @@ pattern = generate_pattern((calculate_length(meters + 400) + 800) // 200) # Adjust the length as needed (x / 2 - 2) current_datetime = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") -# Store the initial coordinates and initialize lists to store the coordinates for each step -initial_latitude = latitude -initial_longitude = longitude - -# Initialize variables to store coordinates and counts -coordinates = [] -coordinates_count = 0 -coordinates_sum = [0, 0] - -# Extract users with distance 500 -filtered_users = [] - # Initialize an empty dictionary to store user data users_data = {} step = 0 @@ -107,8 +95,8 @@ # Banner logo print(banner) -# Printing geo cordinates -print_geo_coordinater(latitude, longitude) +# Printing geo coordinates +print_geo_coordinates(latitude, longitude) # Printing city and country by coordinates print_city_by_geo(latitude, longitude)