Skip to content

Commit

Permalink
Merge pull request #3 from sekiyaanis/feature-update-20240909
Browse files Browse the repository at this point in the history
Feature update 20240909
  • Loading branch information
sekiyaanis authored Sep 10, 2024
2 parents 76849c1 + ffc9566 commit a5229de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +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/

12 changes: 8 additions & 4 deletions weather.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import os
import requests
import json
from geopy.geocoders import Nominatim
from dotenv import load_dotenv

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 @@ -35,15 +39,15 @@ 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:
print(f"現在地の取得中にエラーが発生しました: {e}")
return None

# OpenWeatherMap APIキーを入力してください
api_key = "cc95156ebbff393d571ecc5448ac784e"
# .envファイルからAPIキーを取得
api_key = os.getenv("OPENWEATHERMAP_API_KEY")

city = get_current_location()
if city:
Expand Down

0 comments on commit a5229de

Please sign in to comment.