jonghhhh commited on
Commit
b931666
Β·
verified Β·
1 Parent(s): 508403c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -30
app.py CHANGED
@@ -3,7 +3,7 @@ import requests
3
  import pandas as pd
4
 
5
  # API ν‚€ μ„€μ •
6
- api_key = "Z2FNKPFTMDSTHHR60KS4"
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
- df = pd.DataFrame(data['StatisticSearch']['row'])
27
- return df
 
 
 
 
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(start=1, end=10):
34
- url = f"https://ecos.bok.or.kr/api/KeyStatisticList/{api_key}/json/kr/{start}/{end}"
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.header("1. 톡계 μ½”λ“œ 쑰회")
49
- stat_codes_df = get_statistic_codes()
50
- if stat_codes_df is not None:
51
- st.dataframe(stat_codes_df)
52
- selected_code = st.selectbox("μ‘°νšŒν•  톡계 μ½”λ“œλ₯Ό μ„ νƒν•˜μ„Έμš”:", stat_codes_df['STAT_CODE'])
53
 
54
- # 톡계 데이터 쑰회 및 좜λ ₯
55
- st.header("2. 톡계 데이터 쑰회")
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
- if st.button("톡계 데이터 쑰회"):
61
- stat_data_df = get_statistic_data(selected_code, period, start_date, end_date)
62
- if stat_data_df is not None:
63
- st.dataframe(stat_data_df)
64
-
65
- st.title("ν•œκ΅­μ€ν–‰ ECOS API 데이터 쑰회")
 
 
 
 
 
 
 
 
 
66
 
67
- # 100λŒ€ ν†΅κ³„μ§€ν‘œ μ‹€μ‹œκ°„ 확인
68
- st.header("100λŒ€ ν†΅κ³„μ§€ν‘œ μ‹€μ‹œκ°„ 확인")
69
-
70
- if st.button("100λŒ€ ν†΅κ³„μ§€ν‘œ 전체 쑰회"):
71
- top_100_df = get_top_100_statistics()
72
- if top_100_df is not None:
73
- st.dataframe(top_100_df)
 
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)