Started the reorganization of Scripts for github. Some notes changes.

This commit is contained in:
Norm Rasmussen
2023-05-04 16:07:06 -04:00
parent 6a674ca24b
commit 18a266746b
209 changed files with 121 additions and 12181 deletions

View File

@ -0,0 +1,59 @@
import markdown
rootdir = "/Users/normrasmussen/Documents/Northpass/Scripts/API_Notes/SampleNotes/"
def findheadings():
headingsarray = []
with open(rootdir + "Flink.md", "r") as myfile:
file = myfile.readlines()
for headings in file:
if "##" in headings:
headingsarray.append(headings)
print(headingsarray)
# From StackOverflow:
def noteSections(rootdir):
# today = date.today()
# today = today.strftime("%m/%d/%Y")
# dateregex = "^[0-9]{1,2}\\/[0-9]{1,2}\\/[0-9]{4}$"
with open(rootdir + "Flink.md", "r") as f:
notes_flag = False
notes = ""
for line in f:
if line.startswith("## "):
notes_flag = True
elif notes_flag:
notes += line
if not line.strip():
break
print(notes)
# mdConvert(rootdir, notes)
def meetingSections(rootdir):
dateregex = "^[0-9]{1,2}\\/[0-9]{1,2}\\/[0-9]{4}$"
currentnote = rootdir + "Flink.md"
with open(currentnote, "r") as f:
text = f.read()
# print(text)
# m = re.search(f"##(.^[0-9]{1,2}\\/[0-9]{1,2}\\/[0-9]{4}$)\n(.*)\n\n")
# m = re.search("##"+dateregex+"(.*)"+"##"+dateregex, text)
if m:
print("Found a section!")
found = m.group(1)
print(found)
def mdConvert(rootdir, notes):
conversion = markdown.markdown(notes)
print(conversion)
# FEAT: Add Conversion variable to payload for hubspot. Copy functions from the other files.
if __name__ == "__main__":
meetingSections(rootdir)
# noteSections(rootdir)

View File

@ -0,0 +1,80 @@
import requests
from requests.auth import HTTPBasicAuth
import json
import os
# Information
#url = "https://northpass.atlassian.net/wiki/rest/api/content/2210463745/child/page"
url = "https://northpass.atlassian.net/wiki/rest/api/content/"
auth = HTTPBasicAuth("nrasmussen@northpass.com", "qf9Il7X4wkthgQKBOIly5737")
rootdir = "/Users/normrasmussen/Documents/Northpass/CustomerNotes/"
def getCompany():
rootdir = "/Users/normrasmussen/Documents/Northpass/Scripts/Confluence_Notes/SampleNotes/"
companyName = os.listdir(rootdir)
for fileName in companyName:
company = fileName[:-3]
getPages(company)
def readNewNotes(company):
rootdir = "/Users/normrasmussen/Documents/Northpass/Scripts/Confluence_Notes/SampleNotes/"
with open(rootdir+company+".md", "r") as companyfile:
notes = companyfile.read()
conversion = markdown.markdown(notes)
createNewPage(company, conversion)
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)
def createNewPage(company, notes):
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"}}
} )
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)
if __name__ == "__main__":
createNewPage()
#readNewNotes(company="Flink")

View File

@ -0,0 +1,46 @@
# This code sample uses the 'requests' library:
# http://docs.python-requests.org
import requests
from requests.auth import HTTPBasicAuth
import json
url = "https://northpass.atlassian.net/wiki/rest/api/content"
#auth = HTTPBasicAuth("bnJhc211c3NlbkBub3J0aHBhc3MuY29tOnFmOUlsN1g0d2t0aGdRS0JPSWx5NTczNw==")
# Find a page CURL
#curl -u admin:admin -X GET "http://localhost:8080/confluence/rest/api/content?title=myPage%20Title&spaceKey=TST&expand=history" | python -mjson.tool
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":"Customer Name",
"ancestors":[{"id":2210463745}],
"space":
{"key":"~350535240"},
"body":
{"storage":
{"value":
"<p>A Customer Page</p> <ac:structured-macro ac:name='expand' ac:schema-version='1'><ac:rich-text-body><p>Customer Content * Item1 * Item 2 1. Item3 2. Item 4</p></ac:rich-text-body></ac:structured-macro>",
"representation":"storage"}}
} )
response = requests.request(
"POST",
url,
data=payload,
headers=headers,
auth=auth
)
response = json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": "))
print(response)
#x = response.split()
#print(x)

View File

@ -0,0 +1,45 @@
# This code sample uses the 'requests' library:
# http://docs.python-requests.org
import requests
from requests.auth import HTTPBasicAuth
import json
url = "https://northpass.atlassian.net/wiki/rest/api/content"
#auth = HTTPBasicAuth("bnJhc211c3NlbkBub3J0aHBhc3MuY29tOnFmOUlsN1g0d2t0aGdRS0JPSWx5NTczNw==")
# Find a page CURL
#curl -u admin:admin -X GET "http://localhost:8080/confluence/rest/api/content?title=myPage%20Title&spaceKey=TST&expand=history" | python -mjson.tool
auth = HTTPBasicAuth("nrasmussen@northpass.com", "qf9Il7X4wkthgQKBOIly5737")
headers = {
"X-Atlassian-Token": "no-check",
"Accept": "application/json",
"Content-Type": "application/json"
}
# Example POST request to https://api.hubspot.com/crm/v3/objects/notes
payload = json.dumps( {
"properties": {
"hs_timestamp": "2021-11-12T15:48:22Z",
"hs_note_body": "Spoke with decision maker Carla. Attached the proposal and draft of contract.",
"hubspot_owner_id": "14240720",
"hs_attachment_ids": "24332474034;24332474044"
}
})
#To associate a note with other CRM records, such as a contact, make a PUT request to /crm/v3/objects/notes/{noteId}/associations/{toObjectType}/{toObjectId}/{associationType}.
response = requests.request(
"POST",
url,
data=payload,
headers=headers,
auth=auth
)
response = json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": "))
print(response)
#x = response.split()
#print(x)

View File

@ -0,0 +1,118 @@
import markdown
import requests
from requests.auth import HTTPBasicAuth
import json
import sys
input = sys.argv[1]
company = input.split("/")[6]
def readFile(company):
rootdir = "/Users/normrasmussen/Documents/Northpass/Scripts/API_Notes/SampleNotes/"
with open(rootdir+company+".md", "r") as companyfile:
notes = companyfile.read()
notes = markdown.markdown(notes)
getContent(company, notes)
def createNewPage(company, notes):
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"}}
} )
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)
exists = "already exists"
# This if statement checks if the response from the call includes that the page already exists.
# If the page does exist, it will get the ID and Version of the page and then run a PUT call to update the page.
if exists in response:
#print("This page exists! Updating page instead.")
getContent(company, notes)
def getContent(company, notes):
url = "https://northpass.atlassian.net/wiki/rest/api/content/search?cql=parent=2210463745&expand=body.storage,version"
# Found the answer to this URL here: https://community.atlassian.com/t5/Confluence-questions/How-can-i-get-the-page-version-using-a-specific-page-id/qaq-p/898721
auth = HTTPBasicAuth("nrasmussen@northpass.com", "qf9Il7X4wkthgQKBOIly5737")
headers = {
"Accept": "application/json",
}
response = requests.request("GET", url, headers=headers, auth=auth)
jsonResponse = response.json()
text = json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",",": "))
#print(text)
listCompanies = []
for response in jsonResponse['results']:
if response['title'] == company:
#print(f"{company} Found.")
version = int(response["version"]["_links"]["self"][-1])
if version == "":
version = 1
else:
pass
id = response['id']
#print(id)
#print(version)
updatePage(company, notes, id, version)
else:
listCompanies.append(response["title"])
pass
#print("Other Companies, not pertinent right now. List of companies:")
#print(listCompanies)
def updatePage(company, notes, id, version):
url = f"https://northpass.atlassian.net/wiki/rest/api/content/{id}"
newVersion = version+1
auth = HTTPBasicAuth("nrasmussen@northpass.com", "qf9Il7X4wkthgQKBOIly5737")
headers = {
"X-Atlassian-Token": "no-check",
"Accept": "application/json",
"Content-Type": "application/json",
"User-Agent" : "python-requests/2.28.1",
}
payload = json.dumps( {
"version": {
"number": newVersion
},
"type":"page",
"title": company,
"status": "curent",
"ancestors":[{"id": 2210463745}],
"body":
{"storage":
{"value": notes,
"representation":"storage"}}
} )
response = requests.request(
"PUT",
url,
data=payload,
headers=headers,
auth=auth
)
response = json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": "))
#print(response)
#print("updatePage function has run")
if __name__ == "__main__":
readFile(company)

View File

@ -0,0 +1,127 @@
import markdown
import requests
from requests.auth import HTTPBasicAuth
import json
import os
def findCompanies():
rootdir = "/Users/normrasmussen/Documents/Northpass/CustomerNotes/"
files = os.listdir(rootdir)
for fileName in files:
if fileName.startswith(".") or fileName.startswith("ima"):
pass
else:
company = fileName[:-3]
#print(company)
readFile(company)
def readFile(company):
rootdir = "/Users/normrasmussen/Documents/Northpass/CustomerNotes/"
with open(rootdir+company+".md", "r") as companyfile:
notes = companyfile.read()
notes = markdown.markdown(notes)
createNewPage(company, notes)
def createNewPage(company, notes):
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"}}
} )
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)
exists = "already exists"
# This if statement checks if the response from the call includes that the page already exists.
# If the page does exist, it will get the ID and Version of the page and then run a PUT call to update the page.
if exists in response:
#print("This page exists! Updating page instead.")
getContent(company, notes)
def getContent(company, notes):
url = "https://northpass.atlassian.net/wiki/rest/api/content/search?cql=parent=2210463745&expand=body.storage,version"
# Found the answer to this URL here: https://community.atlassian.com/t5/Confluence-questions/How-can-i-get-the-page-version-using-a-specific-page-id/qaq-p/898721
auth = HTTPBasicAuth("nrasmussen@northpass.com", "qf9Il7X4wkthgQKBOIly5737")
headers = {
"Accept": "application/json",
}
response = requests.request("GET", url, headers=headers, auth=auth)
jsonResponse = response.json()
#print(jsonResponse[''])
text = json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",",": "))
print(text)
listCompanies = []
for response in jsonResponse['results']:
if response['title'] == company:
#print(f"{company} Found.")
version = int(response["version"]["_links"]["self"][-1])
if version == "":
version = 1
else:
pass
id = response['id']
#print(id)
#print(version)
updatePage(company, notes, id, version)
else:
listCompanies.append(response["title"])
pass
#print("Other Companies, not pertinent right now. List of companies:")
#print(listCompanies)
def updatePage(company, notes, id, version):
url = f"https://northpass.atlassian.net/wiki/rest/api/content/{id}"
newVersion = version+1
auth = HTTPBasicAuth("nrasmussen@northpass.com", "qf9Il7X4wkthgQKBOIly5737")
headers = {
"X-Atlassian-Token": "no-check",
"Accept": "application/json",
"Content-Type": "application/json",
"User-Agent" : "python-requests/2.28.1",
}
payload = json.dumps( {
"version": {
"number": newVersion
},
"type":"page",
"title": company,
"status": "curent",
"ancestors":[{"id": 2210463745}],
"body":
{"storage":
{"value": notes,
"representation":"storage"}}
} )
response = requests.request(
"PUT",
url,
data=payload,
headers=headers,
auth=auth
)
response = json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": "))
#print(response)
#print("updatePage function has run")
if __name__ == "__main__":
findCompanies()

View File

@ -0,0 +1,116 @@
import markdown
import requests
from requests.auth import HTTPBasicAuth
import json
def readFile(company):
rootdir = "/Users/normrasmussen/Documents/Northpass/Scripts/API_Notes/SampleNotes/"
with open(rootdir+company+".md", "r") as companyfile:
notes = companyfile.read()
notes = markdown.markdown(notes)
getContent(company, notes)
def createNewPage(company, notes):
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"}}
} )
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)
exists = "already exists"
if exists in response:
print("This page exists! Updating page instead.")
getContent(company, notes)
def getContent(company, notes):
url = "https://northpass.atlassian.net/wiki/rest/api/content/search?cql=parent=2210463745&expand=body.storage,version"
# Found the answer to this URL here: https://community.atlassian.com/t5/Confluence-questions/How-can-i-get-the-page-version-using-a-specific-page-id/qaq-p/898721
auth = HTTPBasicAuth("nrasmussen@northpass.com", "qf9Il7X4wkthgQKBOIly5737")
headers = {
"Accept": "application/json",
}
response = requests.request("GET", url, headers=headers, auth=auth)
jsonResponse = response.json()
text = json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",",": "))
print(text)
listCompanies = []
for response in jsonResponse['results']:
if response['title'] == company:
print(f"{company} Found.")
version = int(response["version"]["_links"]["self"][-1])
if version == "":
version = 1
else:
pass
id = response['id']
print(id)
print(version)
updatePage(company, notes, id, version)
else:
listCompanies.append(response["title"])
pass
print("Other Companies, not pertinent right now. List of companies:")
print(listCompanies)
def updatePage(company, notes, id, version):
url = f"https://northpass.atlassian.net/wiki/rest/api/content/{id}"
newVersion = version+1
print(newVersion)
auth = HTTPBasicAuth("nrasmussen@northpass.com", "qf9Il7X4wkthgQKBOIly5737")
headers = {
"X-Atlassian-Token": "no-check",
"Accept": "application/json",
"Content-Type": "application/json",
"User-Agent" : "python-requests/2.28.1",
}
payload = json.dumps( {
"version": {
"number": newVersion
},
"type":"page",
"title": company,
"status": "curent",
"ancestors":[{"id": 2210463745}],
"body":
{"storage":
{"value": notes,
"representation":"storage"}}
} )
response = requests.request(
"PUT",
url,
data=payload,
headers=headers,
auth=auth
)
response = json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": "))
print(response)
print("updatePage function has run")
if __name__ == "__main__":
readFile(company="Flink")
#readNewNotes(company="Flink")

View File

@ -0,0 +1,49 @@
import requeearts
# Create a new page from API Docs
# This is in bash
curl -u admin:admin -X POST -H 'Content-Type: application/json' -d '{"type":"page","title":"new page",
"space":{"key":"TST"},"body":{"storage":{"value":"<p>This is <br/> a new page</p>","representation":
"storage"}}}' http://localhost:8080/confluence/rest/api/content/ | python -mjson.tool
# This is an example of updating content
PUT /rest/api/content/456
{
"version": {
"number": 2
},
"title": "My new title",
"type": "page",
"body": {
"storage": {
"value": "<p>New page data.</p>",
"representation": "storage"
}
}
}
# This is a Northpas example in python
import requests
url = "https://api.northpass.com/v2/people/person_uuid/deactivations"
headers = {"accept": "*/*"}
response = requests.post(url, headers=headers)
print(response.text)
# Confluence example in Python
import requests
url = "http/"
import requests
url = "https://api.northpass.com/v2/activities"
headers = {"accept": "application/json"}
response = requests.get(url, headers=headers)
pagename = file(read file)
title = filename
value = file.read()