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
2022-10-14 17:14:14 -04:00
# Information
#url = "https://northpass.atlassian.net/wiki/rest/api/content/2210463745/child/page"
url = " https://northpass.atlassian.net/wiki/rest/api/content/ "
2022-10-11 09:12:11 -04:00
auth = HTTPBasicAuth ( " nrasmussen@northpass.com " , " qf9Il7X4wkthgQKBOIly5737 " )
2022-10-14 17:14:14 -04:00
rootdir = " ~/Documents/Northpass/CustomerNotes/ "
def getCompany ( ) :
rootdir = " /Users/normrasmussen/Documents/Northpass/CustomerNotes/ "
companyName = os . listdir ( rootdir )
for fileName in companyName :
company = fileName [ : - 3 ]
getPages ( company )
2022-10-11 09:12:11 -04:00
2022-10-14 17:14:14 -04:00
def readNewNotes ( company ) :
rootdir = " /Users/normrasmussen/Documents/Northpass/CustomerNotes/ "
with open ( rootdir + company + " .md " , " r " ) as companyfile :
notes = companyfile . readlines ( )
createNewPage ( company , notes )
print ( notes )
2022-10-11 09:12:11 -04:00
2022-10-14 17:14:14 -04:00
def getPages ( company ) :
headers = {
" Accept " : " application/json " ,
}
response = requests . request (
" GET " ,
url ,
headers = headers ,
auth = auth
)
jsonResponse = response . json ( )
for response in jsonResponse [ ' results ' ] :
if response [ ' title ' ] == company :
print ( f " { company } Found. Updating page.... " )
else :
print ( f " { company } not found. Create new page... " )
readNewNotes ( company )
2022-10-11 09:12:11 -04:00
2022-10-14 17:14:14 -04:00
def createNewPage ( company = " Example " ,
notes = " h1. 10/06/2022 \n ' , ' * Cami and Soner to pull their own analytics \n ' , ' * Unsure what those key metrics are \n ' , ' * However, they currently look at: \n ' , ' * Completion % o f courses \n ' , ' * Number of completed courses \n ' , ' * Planning needs to happen about what those analytics are \n ' , ' * Main priorities, cateogries, ensure the front end is Flinky, \n ' , ' * Reduce banner slightly, Cami to send a picture of what she wants \n ' , ' * They want to launch ASAP, but need to find a window that works best \n ' , ' * Wednesdays are generally slow and could be a good transfer day \n ' , ' * Wednesday 10/19 - tentative \n ' , ' \n ' " ) :
url = " https://northpass.atlassian.net/wiki/rest/api/content/ "
auth = HTTPBasicAuth ( " nrasmussen@northpass.com " , " qf9Il7X4wkthgQKBOIly5737 " )
headers = {
" X-Atlassian-Token " : " no-check " ,
" Accept " : " application/json " ,
" Content-Type " : " application/json "
}
payload = json . dumps ( {
" type " : " page " ,
" title " : company ,
" ancestors " : [ { " id " : 2210463745 } ] ,
" space " :
{ " key " : " ~350535240 " } ,
" body " :
{ " storage " :
{ " value " : notes ,
" representation " : " storage " } }
} )
2022-10-11 09:12:11 -04:00
2022-10-14 17:14:14 -04:00
response = requests . request (
" POST " ,
url ,
data = payload ,
headers = headers ,
auth = auth
)
print ( " createNewPage function has run " )
response = json . dumps ( json . loads ( response . text ) , sort_keys = True , indent = 4 , separators = ( " , " , " : " ) )
print ( response )
#jsonResponse = response.json()
#print(jsonResponse)
2022-10-11 09:12:11 -04:00
2022-10-14 17:14:14 -04:00
if __name__ == " __main__ " :
createNewPage ( )
#readNewNotes(company="Flink")