I am attempting to merge multiple XBRL files into a single excel/csv export. The number of files to be merged is variable and will be dependent on how many are in the specified folder. The code works to export a single file to csv. The only differentiations are the file date and values, all codes/keys in the file are the same. I am stuck on how to cycle through the file_list and consolidate/parse the data into a format for export. A secondary goal is to create a dict containing all the individual report dicts.
import os, glob, pandas as pd, xbrl, csv
from xbrl import XBRLParser, GAAP, GAAPSerializer
path = 'P:/Bank Research/Bank Automation/Calls'
callCert = '57944'
dates = ['063023','123122','123121','123120','123119','123118']
xbrl_parser = XBRLParser()
file_list = glob.glob(path + "/*.XBRL")
['P:/Bank Research/Bank Automation/Calls\Call_Cert57944_033123.XBRL', Call_Cert57944_063023.XBRL', Call_Cert57944_123118.XBRL', Call_Cert57944_123119.XBRL',
xbrl_file = "Call_Cert"+callCert+"_"+dates[0]+".XBRL"
xbrl_document = xbrl_parser.parse(xbrl_file)
custom_obj = xbrl_parser.parseCustom(xbrl_document)
list_bank_numbers = []
list_bank_keys = []
for i in custom_obj():
list_bank_numbers.append(i[1])
list_bank_keys.append(i[0])
bank_dict = {list_bank_keys[i]: list_bank_numbers[i] for i in range(len(list_bank_keys))}
def export_dict_to_csv(dictionary, output_file):
keys = dictionary.keys()
values = dictionary.values()
with open(output_file, 'w', newline='') as csv_file:
writer = csv.writer(csv_file)
writer.writerow(keys)
writer.writerow(values)
export_dict_to_csv(bank_dict, callCert+'.csv')