How To Filter Filenames With Extension On Api Call?
I was working on the python confluence API for downloading attachment from confluence page, I need to download only files with .mpp extension. Tried with glob and direct parameters
Solution 1:
glob.glob()
operates on your local folder. So you can't use that as a filter for get_attachments_from_content()
. Also, don't specify a limit
of since that gets you just one/the first attachment. Specify a high limit or whatever default will include all of them. (You may have to paginate results.)
However, you can exclude the files you don't want by checking the title
of each attachment before you download it, which you have as fname = attachment['title']
.
attachments_container = confluence.get_attachments_from_content(page_id=33110, limit=1000)
attachments = attachments_container['results']
for attachment in attachments:
fname = attachment['title']
ifnot fname.lower().endswith('.mpp'):
# skip file if it's not got that extensioncontinue
download_link = ...
# rest of your code here
Also, your code looks like a copy-paste from this answer but you've changed the actual "downloading" part of it. So if your next StackOverflow question is going to be "how to download a file from confluence", use that answer's code.
Post a Comment for "How To Filter Filenames With Extension On Api Call?"