dgunning / edgartools

Python library for working with SEC Edgar
MIT License
324 stars 70 forks source link

How to download submissio file #26

Closed peiyaoli closed 5 months ago

peiyaoli commented 5 months ago

Really appreciate you have created such an awesome library.

Here is one issue we came up with:

After I fetched attachment Screenshot 2024-01-24 100034

I need to download last text file, here is my code:

with open("my_file.txt", "wb") as binary_file:
    submission_txt = filing.attachments[14].download()
    # Write bytes to file
    binary_file.write(submission_txt)

It showed error, can I resolve this issue?

dgunning commented 5 months ago

Do you have the accession number for the filing you are trying to download, so I can reproduce?

The submission file is text not binary and so open("my_file.txt", "w") should work

Or download as string then .encode('utf-8') to convert to binary

Other ways

from path lib import Path
Path('file.txt').write_bytes(filing.full_text_submission().encode('utf-8'))

To download an image file

Path('image.jpg').write_bytes(filing.attachments[2].download())
dgunning commented 5 months ago

Please check if that solution works for you

dgunning commented 5 months ago

Closing this issue.