import requests
import streamlit as st
def get_weather(city, api_key):
url = f"<http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric>"
response = requests.get(url)
weather_data = response.json()
return weather_data
def main():
st.title("도시 날씨 알리미")
city = st.text_input("도시 이름을 입력하세요.")
api_key = "your api key" # 여기에 OpenWeatherMap API 키를 넣으세요.
if st.button("날씨 조회"):
weather_data = get_weather(city, api_key)
if weather_data["cod"] == 200:
temperature = weather_data["main"]["temp"]
st.write(f"{city}의 현재 기온: {temperature}°C")
else:
st.write("날씨 정보를 가져오는 중에 오류가 발생했습니다.")
if __name__ == "__main__":
main()
주요 도시 이름을 선택할 수 있게
import requests
import streamlit as st
def get_weather(city, api_key):
url = f"<http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric>"
response = requests.get(url)
weather_data = response.json()
return weather_data
def main():
st.title("도시 날씨 알리미")
cities = ["Seoul", "Busan", "Incheon", "Daegu", "Gwangju"] # 한국의 주요 도시 5개 (영문 표기)
city = st.selectbox("도시를 선택하세요.", cities)
api_key = "YOUR_API_KEY" # 여기에 OpenWeatherMap API 키를 넣으세요.
if st.button("날씨 조회"):
weather_data = get_weather(city, api_key)
if weather_data["cod"] == 200:
temperature = weather_data["main"]["temp"]
st.write(f"{city}의 현재 기온: {temperature}°C")
else:
st.write("날씨 정보를 가져오는 중에 오류가 발생했습니다.")
if __name__ == "__main__":
main()
import pandas as pd
import requests
import streamlit as st
def get_weather(city, api_key):
url = f"<http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric>"
response = requests.get(url)
weather_data = response.json()
return weather_data
def update_temperatures(dataframe, api_key):
updated_dataframe = dataframe.copy()
for index, row in updated_dataframe.iterrows():
city = row["City"]
weather_data = get_weather(city, api_key)
if weather_data["cod"] == 200:
temperature = weather_data["main"]["temp"]
updated_dataframe.loc[index, "Temperature"] = temperature
else:
updated_dataframe.loc[index, "Temperature"] = "Error"
return updated_dataframe
def main():
st.title("도시 날씨 알리미")
uploaded_file = st.file_uploader("도시와 온도 항목이 있는 엑셀 파일을 업로드하세요.", type=["xlsx", "xls"])
if uploaded_file is not None:
df = pd.read_excel(uploaded_file)
api_key = "Your Keys" # 여기에 OpenWeatherMap API 키를 넣으세요.
st.write("업로드된 엑셀 파일:")
st.dataframe(df)
if st.button("온도 업데이트"):
updated_df = update_temperatures(df, api_key)
st.write("온도 업데이트 완료:")
st.dataframe(updated_df)
if __name__ == "__main__":
main()