Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download only one type of files (PDF) #79

Open
mabusdogma opened this issue Aug 25, 2022 · 1 comment
Open

Download only one type of files (PDF) #79

mabusdogma opened this issue Aug 25, 2022 · 1 comment

Comments

@mabusdogma
Copy link

mabusdogma commented Aug 25, 2022

Your scripts are great! I wonder how to dowload ony one type of attachments, for example PDFs or Excel files.

@mabusdogma
Copy link
Author

mabusdogma commented Aug 25, 2022

Nevermind, I got it!
This is an example to download only Excel files, from unread emails, 7 or less days old:

from simplegmail import Gmail
from simplegmail.query import construct_query

gmail = Gmail()
query_params = {
    "newer_than": (7, "day"),
    "unread": True,
    "spec_attachment":'xlsx', #PDF or whatever you want
}

messages = gmail.get_messages(query=construct_query(query_params))

try:
 message = messages[0]
 if message.attachments:
    for attm in message.attachments:
        print('File: ' + attm.filename)
        attm.save()  # downloads and saves each attachment under it's stored
                     # filename. You can download without saving with `attm.download()`
except:
 print("Error, probably no specified files found")
 exit()


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant