You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.0 KiB
37 lines
1.0 KiB
import requests
|
|
from requests.auth import HTTPBasicAuth
|
|
import os
|
|
|
|
organization = "hhdelfland"
|
|
project = "Delfland.EAM_OBS_beheer"
|
|
wiki = "Delfland.EAM_OBS_beheer.wiki"
|
|
pat = os.getenv(
|
|
"AZURE_PAT") or "PLAK JE ACCESS TOKEN HIER TUSSEN DE AANHALINGSTEKENS"
|
|
|
|
url = f"https://dev.azure.com/{organization}/{project}/_apis/wiki/wikis/{wiki}/pages?api-version=7.1-preview.1&recursionLevel=full"
|
|
auth = HTTPBasicAuth('', pat)
|
|
|
|
response = requests.get(url, auth=auth)
|
|
|
|
|
|
def generate_toc(pages, indent=0):
|
|
toc = ""
|
|
for page in pages:
|
|
title = page["path"].split("/")[-1]
|
|
url = page.get("remoteUrl")
|
|
if url:
|
|
toc += " " * indent + f"- [{title}]({url})\n"
|
|
if "subPages" in page:
|
|
toc += generate_toc(page["subPages"], indent + 1)
|
|
return toc
|
|
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
toc = generate_toc(data.get("subPages", []))
|
|
print("# Wiki TOC\n")
|
|
print(toc)
|
|
else:
|
|
print("Fout bij ophalen wiki-pagina's:", response.status_code)
|
|
print(response.text)
|