add get_attachments and get_attachment_by_id
This commit is contained in:
parent
9322159d2a
commit
a23d9e6d2e
22
WikiUtils.py
22
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
|
||||
|
|
Loading…
Reference in New Issue