-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e480cd
commit 2b8e6d7
Showing
5 changed files
with
372 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import requests | ||
import pandas as pd | ||
|
||
|
||
class Nts: | ||
""" | ||
NTS Open API 클래스 | ||
""" | ||
|
||
def __init__(self, serviceKey=None): | ||
self.serviceKey = serviceKey | ||
self.url_dict = { | ||
"진위확인": "https://api.odcloud.kr/api/nts-businessman/v1/validate", | ||
"상태조회": "https://api.odcloud.kr/api/nts-businessman/v1/status", | ||
} | ||
|
||
def validate(self, businesses): | ||
""" | ||
사업자등록정보 진위확인 API | ||
Parameters | ||
---------- | ||
businesses : list, DataFrame | ||
사업자등록정보 리스트 (1회 호출 시 최대 100개까지 조회 가능) | ||
Returns | ||
------- | ||
DataFrame | ||
진위확인 결과 | ||
""" | ||
url = self.url_dict["진위확인"] | ||
params = { | ||
"serviceKey": self.serviceKey, | ||
} | ||
if type(businesses) == pd.DataFrame: | ||
businesses = businesses.to_dict("records") | ||
json_data = { | ||
"businesses": businesses, | ||
} | ||
try: | ||
response = requests.post(url, params=params, json=json_data) | ||
df = pd.json_normalize(response.json()['data']) | ||
except Exception as e: | ||
print("Error") | ||
print(e) | ||
return | ||
return df | ||
|
||
def status(self, b_no): | ||
""" | ||
사업자등록정보 상태조회 API | ||
Parameters | ||
---------- | ||
b_no : list | ||
사업자등록번호 (1회 호출 시 최대 100개까지 조회 가능) | ||
Returns | ||
------- | ||
DataFrame | ||
상태조회 결과 | ||
""" | ||
url = self.url_dict["상태조회"] | ||
params = { | ||
"serviceKey": self.serviceKey, | ||
} | ||
data = { | ||
"b_no": b_no, | ||
} | ||
try: | ||
response = requests.post(url, params=params, json=data) | ||
df = pd.DataFrame(response.json()['data']) | ||
except Exception as e: | ||
print("Error") | ||
print(e) | ||
return | ||
return df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
__version__ = "1.0.5" | ||
__version__ = "1.0.6" | ||
__author__ = "정우일(Wooil Jeong)" | ||
__contact__ = "[email protected]" | ||
__github__ = "https://github.com/WooilJeong/PublicDataReader" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,290 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"ExecuteTime": { | ||
"end_time": "2022-12-02T08:23:39.858809Z", | ||
"start_time": "2022-12-02T08:23:39.839859Z" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"import sys\n", | ||
"from pathlib import Path\n", | ||
"sys.path.append(str(Path(os.getcwd()).parent))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from config import API_KEY_INFO\n", | ||
"serviceKey1 = API_KEY_INFO.get(\"portal\")\n", | ||
"serviceKey2 = API_KEY_INFO.get(\"portal2\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import requests\n", | ||
"import pandas as pd" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"class Nts:\n", | ||
"\n", | ||
" def __init__(self, serviceKey=None):\n", | ||
" self.serviceKey = serviceKey\n", | ||
" self.url_dict = {\n", | ||
" \"진위확인\": \"https://api.odcloud.kr/api/nts-businessman/v1/validate\",\n", | ||
" \"상태조회\": \"https://api.odcloud.kr/api/nts-businessman/v1/status\",\n", | ||
" }\n", | ||
"\n", | ||
" def validate(self, businesses):\n", | ||
" \"\"\"\n", | ||
" 사업자등록정보 진위확인 API\n", | ||
"\n", | ||
" Parameters\n", | ||
" ----------\n", | ||
" businesses : list, DataFrame\n", | ||
" 사업자등록정보 리스트 (1회 호출 시 최대 100개까지 조회 가능)\n", | ||
" \n", | ||
" Returns\n", | ||
" -------\n", | ||
" DataFrame\n", | ||
" 진위확인 결과\n", | ||
" \"\"\"\n", | ||
" url = self.url_dict[\"진위확인\"]\n", | ||
" params = {\n", | ||
" \"serviceKey\": self.serviceKey,\n", | ||
" }\n", | ||
" if type(businesses) == pd.DataFrame:\n", | ||
" businesses = businesses.to_dict(\"records\")\n", | ||
" json_data = {\n", | ||
" \"businesses\": businesses,\n", | ||
" }\n", | ||
" try:\n", | ||
" response = requests.post(url, params=params, json=json_data)\n", | ||
" df = pd.json_normalize(response.json()['data'])\n", | ||
" except Exception as e:\n", | ||
" print(\"Error\")\n", | ||
" print(e)\n", | ||
" return\n", | ||
" return df\n", | ||
" \n", | ||
" def status(self, b_no):\n", | ||
" \"\"\"\n", | ||
" 사업자등록정보 상태조회 API\n", | ||
"\n", | ||
" Parameters\n", | ||
" ----------\n", | ||
" b_no : list\n", | ||
" 사업자등록번호 (1회 호출 시 최대 100개까지 조회 가능)\n", | ||
"\n", | ||
" Returns\n", | ||
" -------\n", | ||
" DataFrame\n", | ||
" 상태조회 결과\n", | ||
" \"\"\"\n", | ||
" url = self.url_dict[\"상태조회\"]\n", | ||
" params = {\n", | ||
" \"serviceKey\": self.serviceKey,\n", | ||
" }\n", | ||
" data = {\n", | ||
" \"b_no\": b_no,\n", | ||
" }\n", | ||
" try:\n", | ||
" response = requests.post(url, params=params, json=data)\n", | ||
" df = pd.DataFrame(response.json()['data'])\n", | ||
" except Exception as e:\n", | ||
" print(\"Error\")\n", | ||
" print(e)\n", | ||
" return\n", | ||
" return df" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"- 진위확인" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# 예제 데이터\n", | ||
"data_list = [\n", | ||
" {\n", | ||
" 'b_no': '',\n", | ||
" 'start_dt': '',\n", | ||
" 'p_nm': '',\n", | ||
" 'p_nm2': '',\n", | ||
" 'b_nm': '',\n", | ||
" 'corp_no': '',\n", | ||
" 'b_sector': '',\n", | ||
" 'b_type': ''\n", | ||
" },\n", | ||
" {\n", | ||
" 'b_no': '',\n", | ||
" 'start_dt': '',\n", | ||
" 'p_nm': '',\n", | ||
" 'p_nm2': '',\n", | ||
" 'b_nm': '',\n", | ||
" 'corp_no': '',\n", | ||
" 'b_sector': '',\n", | ||
" 'b_type': ''\n", | ||
" },\n", | ||
"]\n", | ||
"\n", | ||
"data_frame = pd.DataFrame(data_list)\n", | ||
"data_frame" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# NTS API 인스턴스 생성\n", | ||
"API = Nts(serviceKey2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# 진위확인 API 호출\n", | ||
"data = API.validate(data_frame)\n", | ||
"data" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"- 상태조회" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# 사업자등록번호 리스트 (1회 호출 시 최대 100개까지 가능)\n", | ||
"b_no = [\n", | ||
" \"\",\n", | ||
"]\n", | ||
"\n", | ||
"# 진위확인 API 호출\n", | ||
"data = API.status(b_no=b_no)\n", | ||
"data" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"hide_input": false, | ||
"kernelspec": { | ||
"display_name": "base", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.12" | ||
}, | ||
"toc": { | ||
"base_numbering": 1, | ||
"nav_menu": {}, | ||
"number_sections": true, | ||
"sideBar": true, | ||
"skip_h1_title": false, | ||
"title_cell": "Table of Contents", | ||
"title_sidebar": "Contents", | ||
"toc_cell": false, | ||
"toc_position": { | ||
"height": "calc(100% - 180px)", | ||
"left": "10px", | ||
"top": "150px", | ||
"width": "234.707px" | ||
}, | ||
"toc_section_display": true, | ||
"toc_window_display": true | ||
}, | ||
"varInspector": { | ||
"cols": { | ||
"lenName": 16, | ||
"lenType": 16, | ||
"lenVar": 40 | ||
}, | ||
"kernels_config": { | ||
"python": { | ||
"delete_cmd_postfix": "", | ||
"delete_cmd_prefix": "del ", | ||
"library": "var_list.py", | ||
"varRefreshCmd": "print(var_dic_list())" | ||
}, | ||
"r": { | ||
"delete_cmd_postfix": ") ", | ||
"delete_cmd_prefix": "rm(", | ||
"library": "var_list.r", | ||
"varRefreshCmd": "cat(var_dic_list()) " | ||
} | ||
}, | ||
"oldHeight": 237.13578, | ||
"position": { | ||
"height": "440.117px", | ||
"left": "491.674px", | ||
"right": "20px", | ||
"top": "85.9445px", | ||
"width": "613.965px" | ||
}, | ||
"types_to_exclude": [ | ||
"module", | ||
"function", | ||
"builtin_function_or_method", | ||
"instance", | ||
"_Feature" | ||
], | ||
"varInspector_section_display": "block", | ||
"window_display": false | ||
}, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "bf36e43d91273cda28ef8173803dc98b9ff2c112c9a311d9da2b51870a73ee88" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |