Skip to content

Commit

Permalink
add easy setup for API-key, replace nordic and kelvin to celsius
Browse files Browse the repository at this point in the history
  • Loading branch information
torave committed Mar 30, 2025
1 parent e276f2e commit ba86807
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/my_package/setup.py
Original file line number Diff line number Diff line change
@@ -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()
12 changes: 12 additions & 0 deletions src/my_package/util.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ba86807

Please sign in to comment.