jonghhhh commited on
Commit
d6b7cd0
·
verified ·
1 Parent(s): 0d17e10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -36
app.py CHANGED
@@ -94,22 +94,17 @@ def get_statistical_metadata(data_name, start=1, end=10):
94
  def display_data_as_table(data):
95
  if data:
96
  if isinstance(data, dict):
97
- if "StatisticItemList" in data:
98
- df = pd.DataFrame(data["StatisticItemList"]["row"])
99
- elif "StatisticTableList" in data:
100
- df = pd.DataFrame(data["StatisticTableList"]["row"])
101
- elif "StatisticWordList" in data:
102
- df = pd.DataFrame(data["StatisticWordList"]["row"])
103
- elif "KeyStatisticList" in data:
104
- df = pd.DataFrame(data["KeyStatisticList"]["row"])
105
- elif "StatisticMeta" in data:
106
- df = pd.DataFrame(data["StatisticMeta"]["row"])
107
  else:
108
  st.write("데이터를 표시할 수 없습니다.")
109
- return
110
- st.dataframe(df)
111
  else:
112
  st.write("데이터 형식이 잘못되었습니다.")
 
 
113
 
114
  # Streamlit 앱 구성
115
  st.title("한국은행 ECOS API 데이터 조회")
@@ -121,38 +116,47 @@ option = st.sidebar.selectbox(
121
  ("서비스 통계 목록", "통계용어사전", "통계 세부항목 목록", "통계 조회 조건 설정", "100대 통계지표", "통계 메타DB")
122
  )
123
 
124
- # 항목에 따라 데이터를 조회하고 화면에 표로 출력
125
  if option == "서비스 통계 목록":
126
- data = get_service_statistics()
127
- display_data_as_table(data)
 
 
128
 
129
  elif option == "통계용어사전":
130
- term = st.text_input("용어 입력:", "소비자동향지수")
131
- if term:
132
- data = get_statistical_glossary(term)
133
- display_data_as_table(data)
 
134
 
135
  elif option == "통계 세부항목 목록":
136
- stat_code = st.text_input("통계 코드 입력:", "064Y001")
137
- if stat_code:
138
- data = get_statistic_detail_items(stat_code)
139
- display_data_as_table(data)
 
140
 
141
  elif option == "통계 조회 조건 설정":
142
- stat_code = st.text_input("통계 코드 입력:", "064Y001")
143
- period = st.text_input("주기 입력 (예: A, Q, M):", "A")
144
- start_date = st.text_input("검색 시작일자 입력 (예: 2015, 2015Q1, 201501, 20150101):", "2015")
145
- end_date = st.text_input("검색 종료일자 입력 (예: 2021, 2021Q1, 202101, 20210101):", "2021")
146
- if stat_code and period and start_date and end_date:
147
- data = get_statistic_search_conditions(stat_code, period, start_date, end_date)
148
- display_data_as_table(data)
 
149
 
150
  elif option == "100대 통계지표":
151
- data = get_top_100_statistics()
152
- display_data_as_table(data)
 
 
 
153
 
154
  elif option == "통계 메타DB":
155
- data_name = st.text_input("데이터명 입력:", "경제심리지수")
156
- if data_name:
157
- data = get_statistical_metadata(data_name)
158
- display_data_as_table(data)
 
 
94
  def display_data_as_table(data):
95
  if data:
96
  if isinstance(data, dict):
97
+ if any(key in data for key in ["StatisticItemList", "StatisticTableList", "StatisticWordList", "KeyStatisticList", "StatisticMeta"]):
98
+ for key in data:
99
+ if key in ["StatisticItemList", "StatisticTableList", "StatisticWordList", "KeyStatisticList", "StatisticMeta"]:
100
+ df = pd.DataFrame(data[key]["row"])
101
+ st.dataframe(df)
 
 
 
 
 
102
  else:
103
  st.write("데이터를 표시할 수 없습니다.")
 
 
104
  else:
105
  st.write("데이터 형식이 잘못되었습니다.")
106
+ else:
107
+ st.write("데이터를 로드할 수 없습니다.")
108
 
109
  # Streamlit 앱 구성
110
  st.title("한국은행 ECOS API 데이터 조회")
 
116
  ("서비스 통계 목록", "통계용어사전", "통계 세부항목 목록", "통계 조회 조건 설정", "100대 통계지표", "통계 메타DB")
117
  )
118
 
119
+ # 입력 양식 구성
120
  if option == "서비스 통계 목록":
121
+ stat_code = st.text_input("통계표코드 입력 (선택사항):")
122
+ if st.button("실행"):
123
+ data = get_service_statistics(stat_code=stat_code)
124
+ display_data_as_table(data)
125
 
126
  elif option == "통계용어사전":
127
+ term = st.text_input("용어 입력:")
128
+ if st.button("실행"):
129
+ if term:
130
+ data = get_statistical_glossary(term)
131
+ display_data_as_table(data)
132
 
133
  elif option == "통계 세부항목 목록":
134
+ stat_code = st.text_input("통계표코드 입력:")
135
+ if st.button("실행"):
136
+ if stat_code:
137
+ data = get_statistic_detail_items(stat_code)
138
+ display_data_as_table(data)
139
 
140
  elif option == "통계 조회 조건 설정":
141
+ stat_code = st.text_input("통계표코드 입력:")
142
+ period = st.text_input("주기 입력 (예: A, Q, M):")
143
+ start_date = st.text_input("검색 시작일자 입력 (예: 2015, 2015Q1, 201501, 20150101):")
144
+ end_date = st.text_input("검색 종료일자 입력 (예: 2021, 2021Q1, 202101, 20210101):")
145
+ if st.button("실행"):
146
+ if stat_code and period and start_date and end_date:
147
+ data = get_statistic_search_conditions(stat_code, period, start_date, end_date)
148
+ display_data_as_table(data)
149
 
150
  elif option == "100대 통계지표":
151
+ start = st.text_input("요청 시작 건수 (예: 1):", "1")
152
+ end = st.text_input("요청 종료 건수 (예: 10):", "10")
153
+ if st.button("실행"):
154
+ data = get_top_100_statistics(start=start, end=end)
155
+ display_data_as_table(data)
156
 
157
  elif option == "통계 메타DB":
158
+ data_name = st.text_input("데이터명 입력:")
159
+ if st.button("실행"):
160
+ if data_name:
161
+ data = get_statistical_metadata(data_name)
162
+ display_data_as_table(data)