Beispiel #1
0
def get_corp_code() -> OrderedDict:
    """ DART에 등록되어있는 공시대상회사의 고유번호,회사명,대표자명,종목코드, 최근변경일자 다운로드

    Returns
    -------
    OrderedDict
        고유번호 및 회사 정보
    """
    import tempfile

    with tempfile.TemporaryDirectory() as path:
        url = 'https://opendart.fss.or.kr/api/corpCode.xml'

        # Set API KEY
        api_key = get_api_key()
        payload = {'crtfc_key': api_key}

        # Request Download
        resp = request.download(url=url, path=path, payload=payload)
        download_path = resp['full_path']
        cache_folder = get_cache_folder()

        # Unzip File in User Cache Folder
        unzip_path = unzip(file=download_path, path=cache_folder)

        # Search CORPCODE.xml
        files = search_file(path=unzip_path,
                            filename='CORPCODE',
                            extensions='xml')
        if len(files) == 0:
            raise FileNotFoundError('CORPCODE.xml Not Found')

        file = files[0]
        data = xml_to_dict(file)
        return data['result']['list']
Beispiel #2
0
def download_xbrl(path: str, rcept_no: str, reprt_code: str = None) -> str:
    """ XBRL 파일 다운로드

    Parameters
    ----------
    path: str
        Download Path
    rcept_no: str
        접수번호
    reprt_code: str, optinal
        1분기보고서 : 11013 반기보고서 : 11012 3분기보고서 : 11014 사업보고서 : 11011

    Returns
    -------
    str
        xbrl file path

    """
    import tempfile

    with tempfile.TemporaryDirectory() as temp:
        url = 'https://opendart.fss.or.kr/api/fnlttXbrl.xml'

        # Set API KEY
        api_key = get_api_key()
        payload = {
            'crtfc_key': api_key,
            'rcept_no': rcept_no,
            'reprt_code': reprt_code
        }

        # Request Download
        resp = request.download(url=url, path=temp, payload=payload)
        download_path = resp['full_path']

        # Unzip File in User Cache Folder
        unzip_path = unzip(file=download_path, path=path)

        # Search XBRL file
        files = search_file(path=unzip_path)
        if len(files) == 0:
            raise FileNotFoundError('XBRL File Not Found')

        file = files[0]
        return file
Beispiel #3
0
 def xbrl(self):
     """ XBRL 데이터 반환"""
     import tempfile
     if self._xbrl is None:
         with tempfile.TemporaryDirectory() as path:
             try:
                 file_path = download_xbrl(path=path,
                                           rcept_no=self.rcept_no)
                 self._xbrl = get_xbrl_from_file(file_path)
             except FileNotFoundError:
                 xbrl_attached = self._get_xbrl()
                 if xbrl_attached is not None:
                     zip_path = xbrl_attached.download(path=path)
                     folder_path = unzip(zip_path['full_path'])
                     file = search_file(folder_path)
                     if len(file) > 0:
                         self._xbrl = get_xbrl_from_file(file[0])
                 else:
                     self._xbrl = None
     return self._xbrl