-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
gmail attachments downloader updates #3227
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
Conversation
Reviewer's GuideThis PR introduces a new interactive Gmail Attachment Downloader script leveraging the ezgmail API to search user mail threads by query operators, present formatted results, and download attachments to a specified directory with progress tracking and robust error handling; it also refines project documentation with a comprehensive README update and removes the legacy attachment.py script. Sequence Diagram for Gmail Attachment Download ProcesssequenceDiagram
actor User
participant Script as attachment_downloader.py
participant EZGmail as ezgmail Library
participant GmailAPI as Gmail API
User->>Script: Executes script
Script->>EZGmail: init()
activate EZGmail
EZGmail-->>Script: Authentication status (EMAIL_ADDRESS)
deactivate EZGmail
Script-->>User: Displays "Logged in as: ..."
Script-->>User: Prompts "Enter search query:"
User->>Script: Provides search query
Script->>Script: query_with_attachments = query + " has:attachment"
Script->>EZGmail: search(query_with_attachments)
activate EZGmail
EZGmail->>GmailAPI: Performs search operation
activate GmailAPI
GmailAPI-->>EZGmail: Search results (threads)
deactivate GmailAPI
EZGmail-->>Script: Returns GmailThread objects
deactivate EZGmail
alt No results found
Script-->>User: "No results found..."
else Results found
Script-->>User: Displays formatted results (subject, date)
Script-->>User: Prompts "Download attachments? (y/n):"
User->>Script: Confirms 'y'
Script-->>User: Prompts "Enter download directory:"
User->>Script: Provides directory (or empty)
Script->>Script: download_attachments(threads, dir)
activate Script
loop For each thread and message
Script->>EZGmail: message.downloadAllAttachments()
activate EZGmail
EZGmail->>GmailAPI: Requests attachment data
activate GmailAPI
GmailAPI-->>EZGmail: Attachment data
deactivate GmailAPI
EZGmail-->>Script: Saves files to disk
deactivate EZGmail
Script-->>User: Shows progress/downloaded file names
end
deactivate Script
Script-->>User: "Download complete! ... files saved to ..."
end
alt User cancels download
User->>Script: Confirms 'n'
Script-->>User: "Download canceled. Exiting..."
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @dnoice - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
if download_confirmation in ['y', 'yes']: | ||
# Ask for download directory | ||
custom_dir = input("Enter download directory (leave empty for current directory): ").strip() | ||
download_attachments(result_threads, custom_dir if custom_dir else None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (code-quality): Replace if-expression with or
(or-if-exp-identity
)
download_attachments(result_threads, custom_dir if custom_dir else None) | |
download_attachments(result_threads, custom_dir or None) |
Explanation
Here we find ourselves setting a value if it evaluates toTrue
, and otherwiseusing a default.
The 'After' case is a bit easier to read and avoids the duplication of
input_currency
.
It works because the left-hand side is evaluated first. If it evaluates to
true then currency
will be set to this and the right-hand side will not be
evaluated. If it evaluates to false the right-hand side will be evaluated and
currency
will be set to DEFAULT_CURRENCY
.
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Due to inactivity this pull request has been marked as stale. |
Description
This PR adds a Gmail Attachment Downloader script that allows users to search their Gmail account and download attachments matching specific search criteria. The script has been enhanced with improved error handling, better user interface, custom download directory support, and comprehensive documentation.
Fixes #(issue_no)
Type of change
Checklist:
README.md
[Template for README.md](https://github.com/avinashkranjan/Amazing-Python-Scripts/blob/master/Template%20for%20README.md)
Project Metadata
Category:
Title: Gmail Attachment Downloader
Folder: Gmail_Attachment_Downloader
Requirements: requirements.txt (containing: ezgmail)
Script: attachment_downloader.py
Arguments: None (The script uses interactive prompts)
Contributor: dnoice
Description: A Python script that allows users to search their Gmail using query operators and download attachments matching the search criteria to a specified directory.
Summary by Sourcery
Provide a fully featured Gmail Attachment Downloader with an interactive command-line interface, custom download directory support, robust error handling, and comprehensive documentation
New Features:
Enhancements:
Documentation:
Chores: