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