BIG
DBMS : MariaDB 10.x 를 설치하여 사용하였습니다.
Step.1 DB Table 생성
create or replace table yym_project_eis.OpenDart_01_corpCode
(
odcc_01_pk bigint auto_increment primary key,
odcc_01_corp_code varchar(200) null,
odcc_01_corp_name varchar(200) null,
odcc_01_stock_code varchar(200) null,
odcc_01_modify_date varchar(200) null
);
Step.2 기업코드 DATA Parsing AND Data Insert
# -*- coding: utf-8 -*-
# OpenDartAPI 기업코드 정보 파일 다운로드 받기 - https://opendart.fss.or.kr/guide/detail.do?apiGrpCd=DS001&apiId=2019018
import sys
import xml.etree.ElementTree as ET
import mysql.connector
class ClassParseXml:
def __init__(self):
self.apiKey = "---------------------------------------"
def getParseXmlTree(self,xmlFilePath):
tree = ET.parse(xmlFilePath)
return tree
if __name__ == '__main__':
dbConn = mysql.connector.connect(
user='[DBUSER]'
, password='[DBPASSWORD]'
, host='[DBHOST]'
, database='[DBNAME]'
)
Obj = ClassParseXml()
tree = Obj.getParseXmlTree("./CORPCODE.xml")
root = tree.getroot()
sql = ""
sql = "insert into OpenDart_01_corpCode (odcc_01_corp_code, odcc_01_corp_name, odcc_01_stock_code,odcc_01_modify_date) values (%s,%s,%s,%s);"
print(sql)
with dbConn:
with dbConn.cursor() as cur:
for row in root.iter("list"):
print("-----------------------------------------------------")
print("corp_code:" + str(row.find('corp_code').text))
print("corp_name:" + str(row.find('corp_name').text))
print("stock_code:" + str(row.find('stock_code').text))
print("modify_date:" + str(row.find('modify_date').text))
cur.execute(sql
, (
str(row.find('corp_code').text).strip()
,str(row.find('corp_name').text).strip()
,str(row.find('stock_code').text).strip()
,str(row.find('modify_date').text).strip()
)
)
dbConn.commit()
sys.exit(0)
LIST
'!!...Python > !!...OpenDartAPI' 카테고리의 다른 글
[python]OpenDartAPI 기업 직원 현황 정보 DBMS insert (0) | 2022.07.27 |
---|---|
[python]OpenDartAPI 기업 재무 정보 DBMS insert (0) | 2022.07.25 |
[python]OpenDartAPI 사업보고서 주요내용 - 직원현황 정보 가져오기 (0) | 2022.07.19 |
[python]OpenDartAPI 기업코드 XML Parsing 하기 (0) | 2022.07.18 |