dgunning / edgartools

Navigate SEC Edgar data in Python
MIT License
428 stars 85 forks source link

Pulling 10-K filings from XBRL for multiple years not just one year #100

Open david08-08 opened 2 weeks ago

david08-08 commented 2 weeks ago

I am trying to pull 10-K for multiple years but I keep getting an error in the output. Can someone please give me some guidance on how to put the code together for this task. Below is what I put together but I keep getting an error. Thank you.

if name == 'main': output_path = Path('/Users/name/Documents/Apple_Financials_2013_2023.xlsx')

with output_path.open('wb') as f:
    with ExcelWriter(f, engine='xlsxwriter') as writer:
        for year in range(2013, 2023 + 1):
            try:
                # Retrieve the 10-K filing for the given year
                filings = Company("AAPL").get_filings(form="10-K")
                filing_for_year = next(filing for filing in filings if filing.filing_date.year == year)

                # Process the XBRL data for the filing
                xbrl = filing_for_year.xbrl()

                # Write the statements to the Excel workbook
                write_statements(xbrl, writer, year)

            except StopIteration:
                print(f"No 10-K filing found for year {year}")
            except Exception as e:
                print(f"Error processing year {year} for AAPL: {str(e)}")
dgunning commented 2 weeks ago

Can you post the error here? Thanks

david08-08 commented 2 weeks ago
Hey Dwight,  How are you? I hope you are doing well. So I am just following up with you. I was wondering if you could give me some guidance on the below code. I am trying to pull multiple years using the below but I keep getting a blank excel file. Please let me know your thoughts as soon as you can. Thank you. # Example usage:if __name__ == '__main__':    output_path = Path('/Users/name/Documents/Apple_Financials_2013_2023.xlsx')        with output_path.open('wb') as f:        with ExcelWriter(f, engine='xlsxwriter') as writer:            for year in range(2013, 2023 + 1):                try:                    # Retrieve the 10-K filing for the given year                    filings = Company("AAPL").get_filings(form="10-K")                    filing_for_year = next(filing for filing in filings if filing.filing_date.year == year)                     # Process the XBRL data for the filing                    xbrl = filing_for_year.xbrl()                     # Write the statements to the Excel workbook                    write_statements(xbrl, writer, year)                 except StopIteration:                    print(f"No 10-K filing found for year {year}")                except Exception as e:                    print(f"Error processing year {year} for AAPL: {str(e)}") From: Dwight Gunning ***@***.***>Date: Wednesday, September 4, 2024 at 8:02 PMTo: dgunning/edgartools ***@***.***>Cc: david08-08 ***@***.***>, Author ***@***.***>Subject: Re: [dgunning/edgartools] Pulling 10-K filings from XBRL for multiple years not just one year (Issue #100)Can you post the error here? Thanks—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
david08-08 commented 2 weeks ago

Example usage:

if name == 'main': output_path = Path('/Users/name/Documents/Apple_Financials_2013_2023.xlsx')

with output_path.open('wb') as f:
    with ExcelWriter(f, engine='xlsxwriter') as writer:
        for year in range(2013, 2023 + 1):
            try:
                # Retrieve the 10-K filing for the given year
                filings = Company("AAPL").get_filings(form="10-K")
                filing_for_year = next(filing for filing in filings if filing.filing_date.year == year)

                # Process the XBRL data for the filing
                xbrl = filing_for_year.xbrl()

                # Write the statements to the Excel workbook
                write_statements(xbrl, writer, year)

            except StopIteration:
                print(f"No 10-K filing found for year {year}")
            except Exception as e:
                print(f"Error processing year {year} for AAPL: {str(e)}")