add get_auth and get_page_export_html

This commit is contained in:
Sarah 2022-02-18 21:22:00 +00:00
parent 0dd1266490
commit 88be36d5cd
1 changed files with 20 additions and 0 deletions

20
WikiUtils.py Normal file
View File

@ -0,0 +1,20 @@
import requests
from bs4 import BeautifulSoup
def get_auth_header(token_id, token_secret):
return {"Authorization": "Token {}:{}".format(token_id, token_secret)}
def get_page_export_html(page_id, wiki_url, token_id, token_secret):
headers = {}
headers.update(get_auth_header(token_id, token_secret))
r = requests.get(wiki_url + "/api/pages/{}/export/html".format(page_id), headers=headers)
soup = BeautifulSoup(r.text, 'html.parser')
elements = soup.find("code").text.strip().split("\n")
headers = elements.pop(0).split(",")
viewings = [dict(zip(headers, row.split(","))) for row in elements]
return viewings