Skip to content

Commit

Permalink
すべてのAPIを.envファイルで定義するように修正。
Browse files Browse the repository at this point in the history
  • Loading branch information
sekiyaanis committed Sep 10, 2024
1 parent d577621 commit ffc9566
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
OPENWEATHERMAP_API_KEY=cc95156ebbff393d571ecc5448ac784e
OPENWEATHERMAP_API_BASE_URL=https://api.openweathermap.org/data/2.5/weather
IPAPI_CO_JSON=https://ipapi.co/json/

4 changes: 2 additions & 2 deletions weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
load_dotenv() # .envファイルを読み込む

def get_weather(api_key, city):
base_url = "http://api.openweathermap.org/data/2.5/weather"
base_url = os.getenv("OPENWEATHERMAP_API_BASE_URL")
params = {
"q": city,
"appid": api_key,
Expand Down Expand Up @@ -39,7 +39,7 @@ def get_weather(api_key, city):

def get_current_location():
try:
response = requests.get('https://ipapi.co/json/')
response = requests.get(os.getenv("IPAPI_CO_JSON"))
data = response.json()
return data['city']
except Exception as e:
Expand Down

0 comments on commit ffc9566

Please sign in to comment.