-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add easy setup for API-key, replace nordic and kelvin to celsius
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |