From ac84255108feee9f1c36083bde802787bd67ff12 Mon Sep 17 00:00:00 2001 From: vista-man <524715@vistacollege.nl> Date: Tue, 28 Jan 2025 09:08:20 +0100 Subject: [PATCH] Translate comments to Dutch and update log message for clarity --- Python/api/api.py | 84 ++++++++++++++--------------- Python/api/weather.log | 4 ++ Python/omgedraaide string/string.py | 3 +- Python/palindroom/palindroom.py | 1 + Python/priemgetal/priemgetal.py | 2 + Python/scrape/scrape.py | 2 +- 6 files changed, 52 insertions(+), 44 deletions(-) create mode 100644 Python/api/weather.log diff --git a/Python/api/api.py b/Python/api/api.py index da46882..9cb5134 100644 --- a/Python/api/api.py +++ b/Python/api/api.py @@ -3,89 +3,89 @@ import time import sys import os -# Class to handle logging to multiple files +# Klasse om te loggen naar meerdere bestanden class Tee: def __init__(self, *files): - # Initialize with a list of file objects to write to + # Initialiseer met een lijst van bestandobjecten om naar te schrijven self.files = files def write(self, obj): - # Write the given object to all files and flush the output + # Schrijf het gegeven object naar alle bestanden en flush de output for f in self.files: f.write(obj) f.flush() def flush(self): - # Flush the output for all files + # Flush de output voor alle bestanden for f in self.files: f.flush() def close(self): - # Close all files + # Sluit alle bestanden for f in self.files: f.close() -# Function to get the latitude and longitude of a city using OpenWeatherMap API +# Functie om de breedte- en lengtegraad van een stad op te halen met de OpenWeatherMap API def get_coordinates(city_name): - api_key = 'cf2b92cba5cdb89baccb2fe05cacb3a5' # API key for OpenWeatherMap - base_url = 'http://api.openweathermap.org/geo/1.0/direct' # Base URL for geocoding API + api_key = 'cf2b92cba5cdb89baccb2fe05cacb3a5' # API-sleutel voor OpenWeatherMap + base_url = 'http://api.openweathermap.org/geo/1.0/direct' # Basis-URL voor geocoding API params = { - 'q': city_name, # City name to query - 'appid': api_key # API key parameter + 'q': city_name, # Stadnaam om te queryen + 'appid': api_key # API-sleutel parameter } - response = requests.get(base_url, params=params) # Make a GET request to the API + response = requests.get(base_url, params=params) # Maak een GET-verzoek naar de API if response.status_code == 200: - data = response.json() # Parse the JSON response + data = response.json() # Parse de JSON-respons if data: - # Return the latitude and longitude of the first result + # Retourneer de breedte- en lengtegraad van het eerste resultaat return data[0]['lat'], data[0]['lon'] else: - # Print an error message if the city is not found - print(f"City {city_name} not found.") + # Print een foutmelding als de stad niet gevonden is + print(f"Stad {city_name} niet gevonden.") return None, None else: - # Print an error message if the API request fails - print(f"Failed to get coordinates for city {city_name}. Error code: {response.status_code}") + # Print een foutmelding als het API-verzoek mislukt + print(f"Kon de coördinaten voor stad {city_name} niet ophalen. Foutcode: {response.status_code}") return None, None -# Function to get the weather data for given coordinates using OpenWeatherMap API +# Functie om de weersgegevens voor gegeven coördinaten op te halen met de OpenWeatherMap API def get_weather(lat, lon, city_name): - api_key = 'cf2b92cba5cdb89baccb2fe05cacb3a5' # API key for OpenWeatherMap - base_url = 'https://api.openweathermap.org/data/2.5/weather' # Base URL for weather API + api_key = 'cf2b92cba5cdb89baccb2fe05cacb3a5' # API-sleutel voor OpenWeatherMap + base_url = 'https://api.openweathermap.org/data/2.5/weather' # Basis-URL voor weer API params = { - 'lat': lat, # Latitude parameter - 'lon': lon, # Longitude parameter - 'appid': api_key, # API key parameter - 'units': 'metric' # Units parameter to get temperature in Celsius + 'lat': lat, # Breedtegraad parameter + 'lon': lon, # Lengtegraad parameter + 'appid': api_key, # API-sleutel parameter + 'units': 'metric' # Eenheden parameter om temperatuur in Celsius te krijgen } - response = requests.get(base_url, params=params) # Make a GET request to the API + response = requests.get(base_url, params=params) # Maak een GET-verzoek naar de API if response.status_code == 200: - data = response.json() # Parse the JSON response - # Print the weather information - print(f"Weather at coordinates ({lat}, {lon}) in {city_name}:") - print(f"Temperature: {data['main']['temp']}°C") - print(f"Weather: {data['weather'][0]['description']}") + data = response.json() # Parse de JSON-respons + # Print de weersinformatie + print(f"Weer op coördinaten ({lat}, {lon}) in {city_name}:") + print(f"Temperatuur: {data['main']['temp']}°C") + print(f"Weer: {data['weather'][0]['description']}") else: - # Print an error message if the API request fails - print(f"Failed to get weather data for coordinates ({lat}, {lon}). Error code: {response.status_code}") + # Print een foutmelding als het API-verzoek mislukt + print(f"Kon de weersgegevens voor coördinaten ({lat}, {lon}) niet ophalen. Foutcode: {response.status_code}") -# Main function to get city name input from the user and fetch weather data +# Hoofdfunctie om de stadnaam van de gebruiker te vragen en de weersgegevens op te halen if __name__ == "__main__": log_file_path = os.path.join(os.path.dirname(__file__), 'weather.log') if os.path.exists(log_file_path): with open(log_file_path, 'a') as log_file: - log_file.write('\n') # Add 2 empty lines before appending new logs + log_file.write('\n') # Voeg 2 lege regels toe voordat nieuwe logs worden toegevoegd with open(log_file_path, 'a') as log_file: - city_name = input("Enter city name: ") # Prompt the user to enter a city name - lat, lon = get_coordinates(city_name) # Get the coordinates of the city + city_name = input("Voer de naam van de stad in: ") # Vraag de gebruiker om een stadnaam in te voeren + lat, lon = get_coordinates(city_name) # Haal de coördinaten van de stad op if lat is not None and lon is not None: - original_stdout = sys.stdout # Save the original stdout + original_stdout = sys.stdout # Sla de originele stdout op tee = Tee(original_stdout, log_file) - sys.stdout = tee # Redirect stdout to both terminal and log file - get_weather(lat, lon, city_name) # Get the weather data for the coordinates - sys.stdout = original_stdout # Reset stdout to original - # Sleep for 5 seconds before exiting to ensure all logs are written + sys.stdout = tee # Redirect stdout naar zowel terminal als logbestand + get_weather(lat, lon, city_name) # Haal de weersgegevens voor de coördinaten op + sys.stdout = original_stdout # Reset stdout naar origineel + # Wacht 5 seconden voordat het script wordt afgesloten om ervoor te zorgen dat alle logs zijn geschreven time.sleep(5) - tee.close() # Close the Tee object to ensure all files are properly closed \ No newline at end of file + tee.close() # Sluit het Tee-object om ervoor te zorgen dat alle bestanden correct worden gesloten \ No newline at end of file diff --git a/Python/api/weather.log b/Python/api/weather.log new file mode 100644 index 0000000..7057ffc --- /dev/null +++ b/Python/api/weather.log @@ -0,0 +1,4 @@ + +Weer op coördinaten (50.8876735, 5.9773285) in Heerlen: +Temperatuur: 7.48°C +Weer: clear sky diff --git a/Python/omgedraaide string/string.py b/Python/omgedraaide string/string.py index 4deed4c..fa5288f 100644 --- a/Python/omgedraaide string/string.py +++ b/Python/omgedraaide string/string.py @@ -1 +1,2 @@ -print("Deez"[::-1]) # Output: "olleh" \ No newline at end of file +# Print de omgekeerde string +print("Deez"[::-1]) # Output: "zeeD" \ No newline at end of file diff --git a/Python/palindroom/palindroom.py b/Python/palindroom/palindroom.py index 0bdd8e1..8b6a0e4 100644 --- a/Python/palindroom/palindroom.py +++ b/Python/palindroom/palindroom.py @@ -1,4 +1,5 @@ def is_palindrome(word): + # Controleer of een woord een palindroom is return word == word[::-1] # Vraag de gebruiker om een woord in te voeren diff --git a/Python/priemgetal/priemgetal.py b/Python/priemgetal/priemgetal.py index 97cf56e..bcb5e19 100644 --- a/Python/priemgetal/priemgetal.py +++ b/Python/priemgetal/priemgetal.py @@ -1,4 +1,5 @@ def is_prime(num): + # Controleer of een getal een priemgetal is if num <= 1: return False for i in range(2, int(num**0.5) + 1): @@ -7,6 +8,7 @@ def is_prime(num): return True def generate_primes(N): + # Genereer een lijst van priemgetallen tot N primes = [] for num in range(2, N + 1): if is_prime(num): diff --git a/Python/scrape/scrape.py b/Python/scrape/scrape.py index 0de63cf..21368e8 100644 --- a/Python/scrape/scrape.py +++ b/Python/scrape/scrape.py @@ -46,4 +46,4 @@ else: print(f"De titels zijn toegevoegd aan {file_path}") -time.sleep(2) # Wacht 5 seconden voordat het script wordt afgesloten +time.sleep(2) # Wacht 2 seconden voordat het script wordt afgesloten