add get_attachments and get_attachment_by_id

This commit is contained in:
Sarah 2022-02-18 23:47:42 +00:00
parent 9322159d2a
commit a23d9e6d2e
1 changed files with 22 additions and 0 deletions

View File

@ -1,3 +1,4 @@
import json
import requests
@ -12,3 +13,24 @@ def get_page_export_html(page_id, wiki_url, token_id, token_secret):
r = requests.get(wiki_url + "/api/pages/{}/export/html".format(page_id), headers=headers)
return r.text
def get_attachments(wiki_url, token_id, token_secret):
headers = {}
headers.update(get_auth_header(token_id, token_secret))
r = requests.get(wiki_url + "/api/attachments/", headers=headers)
attachment_data = json.loads(r.text)['data']
return attachment_data
def get_attachment_id(attachment_name, page_id, wiki_url, token_id, token_secret):
attachment_data = get_attachments(wiki_url, token_id, token_secret)
for attachment in attachment_data:
if attachment['name'] == attachment_name and attachment['uploaded_to'] == page_id:
return attachment['id']
return None