Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import requests
|
|
| 3 |
import pandas as pd
|
| 4 |
|
| 5 |
# API ν€ μ€μ
|
| 6 |
-
api_key = "
|
| 7 |
|
| 8 |
# ν΅κ³ μ½λ μ‘°ν ν¨μ
|
| 9 |
def get_statistic_codes():
|
|
@@ -23,15 +23,19 @@ def get_statistic_data(stat_code, period, start_date, end_date):
|
|
| 23 |
response = requests.get(url)
|
| 24 |
if response.status_code == 200:
|
| 25 |
data = response.json()
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
else:
|
| 29 |
st.error(f"Failed to retrieve data: {response.status_code}")
|
| 30 |
return None
|
| 31 |
|
| 32 |
-
# 100λ ν΅κ³μ§ν μ‘°ν ν¨μ
|
| 33 |
-
def get_top_100_statistics(
|
| 34 |
-
url = f"https://ecos.bok.or.kr/api/KeyStatisticList/{api_key}/json/kr/
|
| 35 |
response = requests.get(url)
|
| 36 |
if response.status_code == 200:
|
| 37 |
data = response.json()
|
|
@@ -44,30 +48,35 @@ def get_top_100_statistics(start=1, end=10):
|
|
| 44 |
# Streamlit μ± κ΅¬μ±
|
| 45 |
st.title("νκ΅μν ECOS API λ°μ΄ν° μ‘°ν")
|
| 46 |
|
| 47 |
-
#
|
| 48 |
-
st.
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
selected_code = st.selectbox("μ‘°νν ν΅κ³ μ½λλ₯Ό μ ννμΈμ:", stat_codes_df['STAT_CODE'])
|
| 53 |
|
| 54 |
-
|
| 55 |
-
st.header("
|
| 56 |
-
period = st.text_input("μ‘°ν μ£ΌκΈ° μ
λ ₯ (μ: A, Q, M):", "A")
|
| 57 |
-
start_date = st.text_input("κ²μ μμμΌμ μ
λ ₯ (μ: 2015, 2015Q1, 201501, 20150101):", "2015")
|
| 58 |
-
end_date = st.text_input("κ²μ μ’
λ£μΌμ μ
λ ₯ (μ: 2021, 2021Q1, 202101, 20210101):", "2021")
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
st.header("100λ ν΅κ³μ§ν μ€μκ° νμΈ")
|
| 69 |
-
|
| 70 |
-
if st.button("100λ ν΅κ³μ§ν μ 체 μ‘°ν"):
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
|
| 5 |
# API ν€ μ€μ
|
| 6 |
+
api_key = "YOUR_API_KEY_HERE"
|
| 7 |
|
| 8 |
# ν΅κ³ μ½λ μ‘°ν ν¨μ
|
| 9 |
def get_statistic_codes():
|
|
|
|
| 23 |
response = requests.get(url)
|
| 24 |
if response.status_code == 200:
|
| 25 |
data = response.json()
|
| 26 |
+
if 'StatisticSearch' in data:
|
| 27 |
+
df = pd.DataFrame(data['StatisticSearch']['row'])
|
| 28 |
+
return df
|
| 29 |
+
else:
|
| 30 |
+
st.error("λ°μ΄ν°κ° μμ΅λλ€. μ
λ ₯ν 쑰건μ νμΈνμΈμ.")
|
| 31 |
+
return None
|
| 32 |
else:
|
| 33 |
st.error(f"Failed to retrieve data: {response.status_code}")
|
| 34 |
return None
|
| 35 |
|
| 36 |
+
# 100λ ν΅κ³μ§ν μ 체 μ‘°ν ν¨μ
|
| 37 |
+
def get_top_100_statistics():
|
| 38 |
+
url = f"https://ecos.bok.or.kr/api/KeyStatisticList/{api_key}/json/kr/1/1000"
|
| 39 |
response = requests.get(url)
|
| 40 |
if response.status_code == 200:
|
| 41 |
data = response.json()
|
|
|
|
| 48 |
# Streamlit μ± κ΅¬μ±
|
| 49 |
st.title("νκ΅μν ECOS API λ°μ΄ν° μ‘°ν")
|
| 50 |
|
| 51 |
+
# μΌμͺ½ μ¬μ΄λλ°μμ μ ν λ©λ΄ ꡬμ±
|
| 52 |
+
menu = st.sidebar.selectbox(
|
| 53 |
+
"λ©λ΄λ₯Ό μ ννμΈμ",
|
| 54 |
+
("ν΅κ³ μ½λ μ‘°ν λ° λ°μ΄ν° λΆμ", "100λ ν΅κ³μ§ν μ€μκ° νμΈ")
|
| 55 |
+
)
|
|
|
|
| 56 |
|
| 57 |
+
if menu == "ν΅κ³ μ½λ μ‘°ν λ° λ°μ΄ν° λΆμ":
|
| 58 |
+
st.header("ν΅κ³ μ½λ μ‘°ν λ° λ°μ΄ν° λΆμ")
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
# ν΅κ³ μ½λ μ‘°ν λ° μ ν
|
| 61 |
+
stat_codes_df = get_statistic_codes()
|
| 62 |
+
if stat_codes_df is not None:
|
| 63 |
+
st.dataframe(stat_codes_df)
|
| 64 |
+
selected_code = st.selectbox("μ‘°νν ν΅κ³ μ½λλ₯Ό μ ννμΈμ:", stat_codes_df['STAT_CODE'])
|
| 65 |
+
|
| 66 |
+
# ν΅κ³ λ°μ΄ν° μ‘°ν λ° μΆλ ₯
|
| 67 |
+
period = st.text_input("μ‘°ν μ£ΌκΈ° μ
λ ₯ (μ: A, Q, M):", "A")
|
| 68 |
+
start_date = st.text_input("κ²μ μμμΌμ μ
λ ₯ (μ: 2015, 2015Q1, 201501, 20150101):", "2015")
|
| 69 |
+
end_date = st.text_input("κ²μ μ’
λ£μΌμ μ
λ ₯ (μ: 2021, 2021Q1, 202101, 20210101):", "2021")
|
| 70 |
+
|
| 71 |
+
if st.button("ν΅κ³ λ°μ΄ν° μ‘°ν"):
|
| 72 |
+
stat_data_df = get_statistic_data(selected_code, period, start_date, end_date)
|
| 73 |
+
if stat_data_df is not None:
|
| 74 |
+
st.dataframe(stat_data_df)
|
| 75 |
|
| 76 |
+
elif menu == "100λ ν΅κ³μ§ν μ€μκ° νμΈ":
|
| 77 |
+
st.header("100λ ν΅κ³μ§ν μ€μκ° νμΈ")
|
| 78 |
+
|
| 79 |
+
if st.button("100λ ν΅κ³μ§ν μ 체 μ‘°ν"):
|
| 80 |
+
top_100_df = get_top_100_statistics()
|
| 81 |
+
if top_100_df is not None:
|
| 82 |
+
st.dataframe(top_100_df)
|