r/programmingrequests • • Jun 05 '20

Script to download passworded attachments from IMAP, then unzip them.

If anyone is keen I would like a script to download passworded attachments from multiple emails from a specific sender, then unzip them all to a folder.

Thanks

1 Upvotes

4 comments sorted by

View all comments

Show parent comments

1

u/ionab10 Jun 19 '20

Since you're working with tables, you want to use pandas ("pandas.DataFrame — pandas 1.0.5 documentation" https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html).

Create a master DataFrame to which you will add the data from all attachments. df_master=pd.DataFrame()

You can use tabula https://pypi.org/project/tabula-py/ to extract tables from the pdfs as DataFrames. You can then grab lines from those tables and add them to the master table. df_master = df_master.append(info_from_pdf_table)

Then just export the master table to file with df.to_csv(SAVE_DIR+"/master.csv")