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

Improved download_attachments_from_page: added filename filter for si… #1476

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AImenes
Copy link

@AImenes AImenes commented Nov 26, 2024

Here’s an improved and generalized version of your pull request comment:


NEW/CHANGE:

download_attachments_from_page Method in confluence.py

  • Backward Compatibility: The existing usage of this method remains unchanged, and can be used as previous for downloading all attachments on page.
  • New Features:
    1. Download by Filename: Added the filename parameter to enable downloading a specific file by its name. This avoids the need to process all attachments when only one file is required.
    2. In-Memory Downloads: Introduced the to_memory parameter. When set to True, files are downloaded as BytesIO objects instead of being written to disk. This is particularly useful when files are passed directly into other pipelines, such as pandas, without intermediate storage.

Example Use Case:

from atlassian import Confluence
import pandas as pd

# Initialize Confluence client
confluence = Confluence(
    url=base_url,
    token=open(token_path, 'r').read().strip(),
)

# Retrieve the page ID
page_id = confluence.get_page_id("some_space", "some_page")

# Download a specific file directly into memory
file_name = "excel_file.xlsx"
file_data = confluence.download_attachments_from_page(page_id=page_id, filename=file_name, to_memory=True)

# Process the file using pandas
excel_data = pd.read_excel(io=file_data.get(file_name))

# Output: DataFrame ready for use in further analysis
print(excel_data)

Other Changes:

  • PEP-8 Compliance: Reorganized imports in confluence.py:
    • Alphabetically ordered standard library, third-party, and local imports.

Anders Imenes added 2 commits November 26, 2024 12:55
…ngle-file-download and in-memory BytesIO option (for pandas loading) in addition to writing to disc.
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

Successfully merging this pull request may close these issues.

1 participant