Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
WooilJeong committed Dec 16, 2022
1 parent 5e480cd commit 2b8e6d7
Show file tree
Hide file tree
Showing 5 changed files with 372 additions and 2 deletions.
77 changes: 77 additions & 0 deletions PublicDataReader/PublicDataPortal/nts.py
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
2 changes: 1 addition & 1 deletion PublicDataReader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

__all__ = [
"__version__", "__author__", "__contact__", "__github__",
"Transaction", "Building", "StoreInfo", "Transportation", "Kosis", "VworldData",
"Transaction", "Building", "StoreInfo", "Transportation", "Kosis", "VworldData", "Kamco", "Nts",
"code_bdong", "get_vworld_data_api_info_by_dataframe", "get_vworld_data_api_info_by_dict",
]
2 changes: 1 addition & 1 deletion PublicDataReader/config/info.py
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"
3 changes: 3 additions & 0 deletions PublicDataReader/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
# 한국자산관리공사 Open API 통합
from PublicDataReader.PublicDataPortal.kamco import Kamco

# 국세청 Open API
from PublicDataReader.PublicDataPortal.nts import Nts

# 코드 데이터 조회
from PublicDataReader.utils.code import code_bdong, get_vworld_data_api_info_by_dataframe, get_vworld_data_api_info_by_dict
290 changes: 290 additions & 0 deletions test/develop.ipynb
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
}

0 comments on commit 2b8e6d7

Please sign in to comment.