diff --git a/WikiUtils.py b/WikiUtils.py index e6ebdcc..390e6cc 100644 --- a/WikiUtils.py +++ b/WikiUtils.py @@ -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