From ba86807b48a261f53bd108439492473ad74dcd14 Mon Sep 17 00:00:00 2001 From: toravest Date: Sun, 30 Mar 2025 21:45:34 +0200 Subject: [PATCH] add easy setup for API-key, replace nordic and kelvin to celsius --- src/my_package/setup.py | 25 +++++++++++++++++++++++++ src/my_package/util.py | 12 ++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/my_package/setup.py create mode 100644 src/my_package/util.py diff --git a/src/my_package/setup.py b/src/my_package/setup.py new file mode 100644 index 0000000..0f18581 --- /dev/null +++ b/src/my_package/setup.py @@ -0,0 +1,25 @@ +import os + +def set_up_API(): + # Define the path to the .env file at the root of the project + env_filepath = os.path.join(os.path.dirname(__file__), "../../.env") + + # Stores the API_EMAIL and API_KEY + API_EMAIL = input("Write your API - email: ") + API_KEY = input("Write your API - key: ") + + # Prints the file path + print(f".env file created at: {env_filepath}") + + # Writes the API_EMAIL and API_KEY + with open (env_filepath, "w") as env_file: + env_file.write(f'API_EMAIL = "{API_EMAIL}"') + env_file.write("\n") + env_file.write(f'API_KEY = "{API_KEY}"') + + # Confirmation messages + print("Values are stored!") + print("You can now run the notebooks, and get data!") + +print("Add your info to OpenWeatherMap.com, and the function will create and add the info to env.") +set_up_API() \ No newline at end of file diff --git a/src/my_package/util.py b/src/my_package/util.py new file mode 100644 index 0000000..2eb13c3 --- /dev/null +++ b/src/my_package/util.py @@ -0,0 +1,12 @@ +def replace_nordic(city_name): + for letter in city_name: + if letter in 'æøå': + city_name = city_name.replace('æ', 'ae') + city_name = city_name.replace('ø', 'o') + city_name = city_name.replace('å', 'aa') + return city_name + + +def kelvin_to_celsius(temp_in_kelvin): + temp_in_celsius = temp_in_kelvin - 273.15 + return temp_in_celsius \ No newline at end of file