Skip to content

Improved download_attachments_from_page: added filename filter for si… #1476

New issue

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

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

Already on GitHub? # to your account

Merged

Conversation

AImenes
Copy link
Contributor

@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.
@gonchik gonchik merged commit 1b49840 into atlassian-api:master Jan 6, 2025
4 of 11 checks passed
@gonchik
Copy link
Member

gonchik commented Jan 6, 2025

@AImenes Thanks, let me adjust for f string

@AImenes AImenes deleted the feature/download-attachments-improvement branch January 7, 2025 08:50
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants