Files
Gainsight/Scripts/Backup_Notes_Scripts/confluence_get.py

80 lines
2.5 KiB
Python
Raw Permalink Normal View History

2022-10-11 09:12:11 -04:00
import requests
from requests.auth import HTTPBasicAuth
import json
2022-10-14 17:14:14 -04:00
import os
2022-10-11 09:12:11 -04:00
2023-05-12 16:45:50 -04:00
# Information
# url = "https://northpass.atlassian.net/wiki/rest/api/content/2210463745/child/page"
2022-10-14 17:14:14 -04:00
url = "https://northpass.atlassian.net/wiki/rest/api/content/"
2023-05-12 16:45:50 -04:00
auth = HTTPBasicAuth("nrasmussen@northpass.com","ATATT3xFfGF0QZUomC1s3hvD4Hiqh_usOVFAVLsT1n8lt6gzD7wfL8D8x5ner3SE24JD4E590xoT9PKPIi1Eppanx12q5ALzMHKce-KrcIZRT23BvO8MDXwyvbzAO2R4hALc8ZUTI_8-OM-x9o_tjbCHLxEMFOr6QFDYprwdHGZjAxpviSwXrCQ=218AC438")
rootdir = "/Users/normrasmussen/Documents/Work/CustomerNotes/"
2022-10-11 09:12:11 -04:00
2022-10-14 17:14:14 -04:00
def getCompany():
2023-05-12 16:45:50 -04:00
rootdir = (
"/Users/normrasmussen/Documents/Work/CustomerNotes/"
)
2022-10-14 17:14:14 -04:00
companyName = os.listdir(rootdir)
for fileName in companyName:
company = fileName[:-3]
getPages(company)
2022-10-11 09:12:11 -04:00
2023-05-12 16:45:50 -04:00
2022-10-14 17:14:14 -04:00
def readNewNotes(company):
2023-05-12 16:45:50 -04:00
rootdir = (
"/Users/normrasmussen/Documents/Work/CustomerNotes/"
)
with open(rootdir + company + ".md", "r") as companyfile:
2022-10-17 16:30:19 -04:00
notes = companyfile.read()
conversion = markdown.markdown(notes)
createNewPage(company, conversion)
2022-10-11 09:12:11 -04:00
2023-05-12 16:45:50 -04:00
2022-10-14 17:14:14 -04:00
def getPages(company):
headers = {
"Accept": "application/json",
}
2023-05-12 16:45:50 -04:00
response = requests.request("GET", url, headers=headers, auth=auth)
2022-10-14 17:14:14 -04:00
jsonResponse = response.json()
2023-05-12 16:45:50 -04:00
for response in jsonResponse["results"]:
if response["title"] == company:
2022-10-14 17:14:14 -04:00
print(f"{company} Found. Updating page....")
else:
print(f"{company} not found. Create new page...")
2023-05-12 16:45:50 -04:00
# readNewNotes(company)
2022-10-11 09:12:11 -04:00
2023-05-12 16:45:50 -04:00
def createNewPage(company, notes):
2022-10-14 17:14:14 -04:00
url = "https://northpass.atlassian.net/wiki/rest/api/content/"
auth = HTTPBasicAuth("nrasmussen@northpass.com", "qf9Il7X4wkthgQKBOIly5737")
headers = {
"X-Atlassian-Token": "no-check",
"Accept": "application/json",
2023-05-12 16:45:50 -04:00
"Content-Type": "application/json",
2022-10-14 17:14:14 -04:00
}
2023-05-12 16:45:50 -04:00
payload = json.dumps(
{
"type": "page",
"title": company,
"ancestors": [{"id": 2210463745}],
"space": {"key": "~350535240"},
"body": {"storage": {"value": notes, "representation": "storage"}},
}
2022-10-14 17:14:14 -04:00
)
2023-05-12 16:45:50 -04:00
response = requests.request("POST", url, data=payload, headers=headers, auth=auth)
2022-10-14 17:14:14 -04:00
print("createNewPage function has run")
2023-05-12 16:45:50 -04:00
response = json.dumps(
json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")
)
2022-10-14 17:14:14 -04:00
print(response)
2023-05-12 16:45:50 -04:00
# jsonResponse = response.json()
# print(jsonResponse)
2022-10-11 09:12:11 -04:00
2022-10-14 17:14:14 -04:00
if __name__ == "__main__":
2023-05-12 16:45:50 -04:00
getCompany()
# createNewPage()
# readNewNotes(company="Flink")