32 lines
924 B
Python
32 lines
924 B
Python
import requests
|
|
import os
|
|
|
|
def get_env_variable(var_name):
|
|
if os.path.exists(".env"):
|
|
with open(".env", "r") as f:
|
|
for line in f:
|
|
if "=" in line:
|
|
k, v = line.split("=", 1)
|
|
if k.strip() == "WEATHER_KEY" or k.strip() == "KMA_API_KEY":
|
|
return v.strip()
|
|
return os.getenv("WEATHER_KEY")
|
|
|
|
API_KEY = get_env_variable("WEATHER_KEY")
|
|
|
|
BASE_URL = "https://apihub.kma.go.kr/api/typ01/url/sfc_nc_var.php"
|
|
params = {
|
|
"tm1": "202604171220",
|
|
"tm2": "202604171220",
|
|
"obs": "ta", # Start with just one
|
|
"lon": 127.712072,
|
|
"lat": 34.924702,
|
|
"help": 1, # Show headers to see columns
|
|
"authKey": API_KEY
|
|
}
|
|
|
|
try:
|
|
print("Checking API column headers...")
|
|
response = requests.get(BASE_URL, params=params, timeout=10)
|
|
print(f"Response:\n{response.text}")
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|