简体   繁体   English

使用 Arelle 获取 XBRL 数据

[英]getting XBRL data with Arelle

After looking over the documentation for arelle on their website, I found the answer.在他们的网站上查看了 areelle 的文档后,我找到了答案。 To retrieve the data you need, you can use arelleCmdLine to export a csv specifying relevant data with --factListCols followed by a string of desired data types (separated by spaces).要检索您需要的数据,您可以使用 arelleCmdLine 导出指定相关数据的 csv,其中 --factListCols 后跟所需数据类型的字符串(以空格分隔)。 Calling arelleCmdLine varies from os.调用 arelleCmdLine 因操作系统而异。

CmdL = 'Applications/Arelle.app/contents/MacOS/arelleCmdLine'
os.system('%s --file %s --factListCols "Name Value Period" --facts %s') % (CmdL,xmlPth,csvPth)

I am trying to get "properties" of facts in the "factlist" of an xbrl document.我试图在 xbrl 文档的“事实列表”中获取事实的“属性”。 The properties hold the "name" data (or the fact's GAAP taxonomy) and the "contextRef" which holds the date data "StartDate," "endDate" and "instant."这些属性包含“名称”数据(或事实的 GAAP 分类法)和“contextRef”,其中包含日期数据“StartDate”、“endDate”和“instant”。

It seems like Arelle is my best bet;似乎 Arelle 是我最好的选择; however, cmdline utilities dont seem to cut it for this inquiry, and the api documentation Here is entirely blank save for the filenames inside the source.但是,cmdline 实用程序似乎并没有为此查询而削减它,而且 api 文档Here是完全空白的,保存了源文件中的文件名。

Is anyone able to explain how to load an xbrl document, load the facts of the fact table and extract the data and meta data from these facts into a list.任何人都能够解释如何加载 xbrl 文档,加载事实表的事实并将这些事实中的数据和元数据提取到列表中。

Below is a bit of code to help clarify the question.下面是一些代码来帮助澄清问题。 When i try to print modeltuplefacts which i believe holds all the facts and there meta data, i get a blank list.当我尝试打印我认为包含所有事实和元数据的模型元组时,我得到一个空白列表。 This code is mostly a copy and paste from CustomLogger.py in example in the arelle folder of the arelle package.该代码主要是一个复制和粘贴从CustomLogger.py在arelle包的arelle夹示例英寸Im unsure how the logger works, but its needed and this example seems to satisfy the Cntlr requirement for it.我不确定记录器是如何工作的,但它是必需的,这个例子似乎满足了 Cntlr 对它的要求。

from __future__ import print_function
import sys
sys.path.insert(0, '~/Desktop/Arelle')
from arelle import Cntlr
from arelle import ModelDocument
from arelle import ModelObject as MO
from arelle import ModelInstanceObject as MIO

class CntlrCustomLoggingExample(Cntlr.Cntlr):

    def __init__(self):
        # no logFileName parameter to prevent default logger from starting
        super().__init__()

    def run(self):
        # start custom logger
        CustomLogHandler(self)

        path = "~/Desktop/SEC/SECindexes10-k/fileHolder/1/nick-20150630.xml"
        modelXbrl = self.modelManager.load(path)

        modelDoc = ModelDocument.load(modelXbrl,path)
        mf = MIO.ModelFact()
        mf.init(modelDoc)
        print(mf.modelTupleFacts)

        self.modelManager.close()

        self.close()

import logging
class CustomLogHandler(logging.Handler):
    def __init__(self, cntlr):
        logger = logging.getLogger("arelle")
        self.level = logging.DEBUG
        self.setFormatter(logging.Formatter("[%(messageCode)s] %(message)s - %(file)s %(sourceLine)s"))
        logger.addHandler(self)

    def emit(self, logRecord):
        # just print to standard output (e.g., terminal window)
        print(self.format(logRecord))

if __name__ == "__main__":
    CntlrCustomLoggingExample().run()

The simplest answer would be to convert the facts from XBRL into .csv and later on manipulate with .csv file in Python searching for appropriate position.最简单的答案是将事实从 XBRL 转换为 .csv,然后在 Python 中使用 .csv 文件进行操作以搜索适当的位置。 here is the simple code for conversion to .csv :这是转换为 .csv 的简单代码:

from arelle import ViewFileFactTable, ModelManager, FileSource, Cntlr, ModelXbrl, ModelDocument

    modelManager = ModelManager.initialize(Cntlr.Cntlr())
    filesource = FileSource.FileSource('C:/XXX/testowy2.xhtml')

    xbrl=ModelXbrl.load(modelManager,'C:/XXX/testowy2.xhtml')

    ViewFileFactTable.viewFacts(xbrl, 'C:/XXX/testowy22.csv')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM