jonghhhh commited on
Commit
9a5d6a9
ยท
verified ยท
1 Parent(s): 38cbbb9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +97 -97
app.py CHANGED
@@ -1,97 +1,97 @@
1
- import streamlit as st
2
- import requests
3
- import pandas as pd
4
-
5
- # API ํ‚ค์™€ ๊ธฐ๋ณธ URL ์„ค์ •
6
- api_key = "YOUR_API_KEY_HERE"
7
- base_url = "https://ecos.bok.or.kr/api/"
8
-
9
- # API ํ˜ธ์ถœ ํ•จ์ˆ˜๋“ค
10
- def get_service_statistics():
11
- url = f"{base_url}StatisticTableList/{api_key}/json/kr/1/1000/"
12
- response = requests.get(url)
13
- return response.json()
14
-
15
- def get_statistical_glossary():
16
- url = f"{base_url}StatisticWordList/{api_key}/json/kr/1/1000/"
17
- response = requests.get(url)
18
- return response.json()
19
-
20
- def get_statistic_detail_items(stat_code):
21
- url = f"{base_url}StatisticItemList/{api_key}/json/kr/1/1000/{stat_code}"
22
- response = requests.get(url)
23
- return response.json()
24
-
25
- def get_statistic_search_conditions(stat_code):
26
- url = f"{base_url}StatisticSearch/{api_key}/json/kr/1/100/{stat_code}"
27
- response = requests.get(url)
28
- return response.json()
29
-
30
- def get_top_100_statistics():
31
- url = f"{base_url}KeyStatisticList/{api_key}/json/kr/1/100/"
32
- response = requests.get(url)
33
- return response.json()
34
-
35
- def get_statistical_metadata():
36
- url = f"{base_url}StatisticMeta/{api_key}/json/kr/1/100/"
37
- response = requests.get(url)
38
- return response.json()
39
-
40
- # JSON ๋ฐ์ดํ„ฐ๋ฅผ DataFrame์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ํ‘œ์‹œ
41
- def display_data_as_table(data):
42
- if isinstance(data, dict):
43
- if "StatisticItemList" in data:
44
- df = pd.DataFrame(data["StatisticItemList"]["row"])
45
- elif "StatisticTableList" in data:
46
- df = pd.DataFrame(data["StatisticTableList"]["row"])
47
- elif "StatisticWordList" in data:
48
- df = pd.DataFrame(data["StatisticWordList"]["row"])
49
- elif "KeyStatisticList" in data:
50
- df = pd.DataFrame(data["KeyStatisticList"]["row"])
51
- elif "StatisticMeta" in data:
52
- df = pd.DataFrame(data["StatisticMeta"]["row"])
53
- else:
54
- st.write("๋ฐ์ดํ„ฐ๋ฅผ ํ‘œ์‹œํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
55
- return
56
- st.dataframe(df)
57
- else:
58
- st.write("๋ฐ์ดํ„ฐ ํ˜•์‹์ด ์ž˜๋ชป๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
59
-
60
- # Streamlit ์•ฑ ๊ตฌ์„ฑ
61
- st.title("ํ•œ๊ตญ์€ํ–‰ ECOS API ๋ฐ์ดํ„ฐ ์กฐํšŒ")
62
- st.sidebar.header("API ํ•ญ๋ชฉ ์„ ํƒ")
63
-
64
- # ์‚ฌ์ด๋“œ๋ฐ”์—์„œ ์„ ํƒํ•  ์ˆ˜ ์žˆ๋Š” ํ•ญ๋ชฉ
65
- option = st.sidebar.selectbox(
66
- "์กฐํšŒํ•  ํ•ญ๋ชฉ์„ ์„ ํƒํ•˜์„ธ์š”:",
67
- ("์„œ๋น„์Šค ํ†ต๊ณ„ ๋ชฉ๋ก", "ํ†ต๊ณ„์šฉ์–ด์‚ฌ์ „", "ํ†ต๊ณ„ ์„ธ๋ถ€ํ•ญ๋ชฉ ๋ชฉ๋ก", "ํ†ต๊ณ„ ์กฐํšŒ ์กฐ๊ฑด ์„ค์ •", "100๋Œ€ ํ†ต๊ณ„์ง€ํ‘œ", "ํ†ต๊ณ„ ๋ฉ”ํƒ€DB")
68
- )
69
-
70
- # ๊ฐ ํ•ญ๋ชฉ์— ๋”ฐ๋ผ ๋ฐ์ดํ„ฐ๋ฅผ ์กฐํšŒํ•˜๊ณ  ํ™”๋ฉด์— ํ‘œ๋กœ ์ถœ๋ ฅ
71
- if option == "์„œ๋น„์Šค ํ†ต๊ณ„ ๋ชฉ๋ก":
72
- data = get_service_statistics()
73
- display_data_as_table(data)
74
-
75
- elif option == "ํ†ต๊ณ„์šฉ์–ด์‚ฌ์ „":
76
- data = get_statistical_glossary()
77
- display_data_as_table(data)
78
-
79
- elif option == "ํ†ต๊ณ„ ์„ธ๋ถ€ํ•ญ๋ชฉ ๋ชฉ๋ก":
80
- stat_code = st.text_input("ํ†ต๊ณ„ ์ฝ”๋“œ ์ž…๋ ฅ:", "064Y001")
81
- if stat_code:
82
- data = get_statistic_detail_items(stat_code)
83
- display_data_as_table(data)
84
-
85
- elif option == "ํ†ต๊ณ„ ์กฐํšŒ ์กฐ๊ฑด ์„ค์ •":
86
- stat_code = st.text_input("ํ†ต๊ณ„ ์ฝ”๋“œ ์ž…๋ ฅ:", "064Y001")
87
- if stat_code:
88
- data = get_statistic_search_conditions(stat_code)
89
- display_data_as_table(data)
90
-
91
- elif option == "100๋Œ€ ํ†ต๊ณ„์ง€ํ‘œ":
92
- data = get_top_100_statistics()
93
- display_data_as_table(data)
94
-
95
- elif option == "ํ†ต๊ณ„ ๋ฉ”ํƒ€DB":
96
- data = get_statistical_metadata()
97
- display_data_as_table(data)
 
1
+ import streamlit as st
2
+ import requests
3
+ import pandas as pd
4
+
5
+ # API ํ‚ค์™€ ๊ธฐ๋ณธ URL ์„ค์ •
6
+ api_key = "Z2FNKPFTMDSTHHR60KS4"
7
+ base_url = "https://ecos.bok.or.kr/api/"
8
+
9
+ # API ํ˜ธ์ถœ ํ•จ์ˆ˜๋“ค
10
+ def get_service_statistics():
11
+ url = f"{base_url}StatisticTableList/{api_key}/json/kr/1/1000/"
12
+ response = requests.get(url)
13
+ return response.json()
14
+
15
+ def get_statistical_glossary():
16
+ url = f"{base_url}StatisticWordList/{api_key}/json/kr/1/1000/"
17
+ response = requests.get(url)
18
+ return response.json()
19
+
20
+ def get_statistic_detail_items(stat_code):
21
+ url = f"{base_url}StatisticItemList/{api_key}/json/kr/1/1000/{stat_code}"
22
+ response = requests.get(url)
23
+ return response.json()
24
+
25
+ def get_statistic_search_conditions(stat_code):
26
+ url = f"{base_url}StatisticSearch/{api_key}/json/kr/1/100/{stat_code}"
27
+ response = requests.get(url)
28
+ return response.json()
29
+
30
+ def get_top_100_statistics():
31
+ url = f"{base_url}KeyStatisticList/{api_key}/json/kr/1/100/"
32
+ response = requests.get(url)
33
+ return response.json()
34
+
35
+ def get_statistical_metadata():
36
+ url = f"{base_url}StatisticMeta/{api_key}/json/kr/1/100/"
37
+ response = requests.get(url)
38
+ return response.json()
39
+
40
+ # JSON ๋ฐ์ดํ„ฐ๋ฅผ DataFrame์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ํ‘œ์‹œ
41
+ def display_data_as_table(data):
42
+ if isinstance(data, dict):
43
+ if "StatisticItemList" in data:
44
+ df = pd.DataFrame(data["StatisticItemList"]["row"])
45
+ elif "StatisticTableList" in data:
46
+ df = pd.DataFrame(data["StatisticTableList"]["row"])
47
+ elif "StatisticWordList" in data:
48
+ df = pd.DataFrame(data["StatisticWordList"]["row"])
49
+ elif "KeyStatisticList" in data:
50
+ df = pd.DataFrame(data["KeyStatisticList"]["row"])
51
+ elif "StatisticMeta" in data:
52
+ df = pd.DataFrame(data["StatisticMeta"]["row"])
53
+ else:
54
+ st.write("๋ฐ์ดํ„ฐ๋ฅผ ํ‘œ์‹œํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
55
+ return
56
+ st.dataframe(df)
57
+ else:
58
+ st.write("๋ฐ์ดํ„ฐ ํ˜•์‹์ด ์ž˜๋ชป๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
59
+
60
+ # Streamlit ์•ฑ ๊ตฌ์„ฑ
61
+ st.title("ํ•œ๊ตญ์€ํ–‰ ECOS API ๋ฐ์ดํ„ฐ ์กฐํšŒ")
62
+ st.sidebar.header("API ํ•ญ๋ชฉ ์„ ํƒ")
63
+
64
+ # ์‚ฌ์ด๋“œ๋ฐ”์—์„œ ์„ ํƒํ•  ์ˆ˜ ์žˆ๋Š” ํ•ญ๋ชฉ
65
+ option = st.sidebar.selectbox(
66
+ "์กฐํšŒํ•  ํ•ญ๋ชฉ์„ ์„ ํƒํ•˜์„ธ์š”:",
67
+ ("์„œ๋น„์Šค ํ†ต๊ณ„ ๋ชฉ๋ก", "ํ†ต๊ณ„์šฉ์–ด์‚ฌ์ „", "ํ†ต๊ณ„ ์„ธ๋ถ€ํ•ญ๋ชฉ ๋ชฉ๋ก", "ํ†ต๊ณ„ ์กฐํšŒ ์กฐ๊ฑด ์„ค์ •", "100๋Œ€ ํ†ต๊ณ„์ง€ํ‘œ", "ํ†ต๊ณ„ ๋ฉ”ํƒ€DB")
68
+ )
69
+
70
+ # ๊ฐ ํ•ญ๋ชฉ์— ๋”ฐ๋ผ ๋ฐ์ดํ„ฐ๋ฅผ ์กฐํšŒํ•˜๊ณ  ํ™”๋ฉด์— ํ‘œ๋กœ ์ถœ๋ ฅ
71
+ if option == "์„œ๋น„์Šค ํ†ต๊ณ„ ๋ชฉ๋ก":
72
+ data = get_service_statistics()
73
+ display_data_as_table(data)
74
+
75
+ elif option == "ํ†ต๊ณ„์šฉ์–ด์‚ฌ์ „":
76
+ data = get_statistical_glossary()
77
+ display_data_as_table(data)
78
+
79
+ elif option == "ํ†ต๊ณ„ ์„ธ๋ถ€ํ•ญ๋ชฉ ๋ชฉ๋ก":
80
+ stat_code = st.text_input("ํ†ต๊ณ„ ์ฝ”๋“œ ์ž…๋ ฅ:", "064Y001")
81
+ if stat_code:
82
+ data = get_statistic_detail_items(stat_code)
83
+ display_data_as_table(data)
84
+
85
+ elif option == "ํ†ต๊ณ„ ์กฐํšŒ ์กฐ๊ฑด ์„ค์ •":
86
+ stat_code = st.text_input("ํ†ต๊ณ„ ์ฝ”๋“œ ์ž…๋ ฅ:", "064Y001")
87
+ if stat_code:
88
+ data = get_statistic_search_conditions(stat_code)
89
+ display_data_as_table(data)
90
+
91
+ elif option == "100๋Œ€ ํ†ต๊ณ„์ง€ํ‘œ":
92
+ data = get_top_100_statistics()
93
+ display_data_as_table(data)
94
+
95
+ elif option == "ํ†ต๊ณ„ ๋ฉ”ํƒ€DB":
96
+ data = get_statistical_metadata()
97
+ display_data_as_table(data)