Files
Gainsight/Scripts/Todo_reorg/parse_for_gstimeline.py

93 lines
2.9 KiB
Python

from pathlib import Path
import requests
import itertools
ndir = Path("/Users/normrasmussen/Documents/Work/CustomerNotes/")
def get_files():
files = list(ndir.glob("**/*.md"))
for company in files:
# This Section gets the Company name for the payload.
company = str(company)
company_file = company.split("/")[-1]
company_name = company_file[:-3]
if company_name == "Bolt":
get_data(company_file, company_name)
def get_data(company_file, company_name):
sdir = "/Users/normrasmussen/Documents/Work/CustomerNotes/"
notes = []
line_num_array = []
text_array = []
company_path = Path(
f"/Users/normrasmussen/Documents/Work/CustomerNotes/{company_file}"
)
with company_path.open(mode="r", encoding="utf-8") as md_file:
line = company_path.read_text()[3]
# This first section finds the lines and adds them to an array.
# It also finds the "date" lines and adds them to a second array.
for num, line in enumerate(md_file):
line = line[:-1]
text_array.append(line)
if line.startswith("## "):
line_num_array.append(num)
# Since I don't know the last line of the file, I take the last
# number in the title array and adds 500,
# going well beyond the last line.
last_line = (line_num_array[-1], 500)
line_num_array.append(sum(last_line))
# This magic pairs each title based on the line numbers.
line_pairs = list(itertools.pairwise(line_num_array))
# We take each "grouping" and add it to an array as each singular item.
for index in line_pairs:
indv_notes = text_array[index[0] : index[1]]
notes.append(indv_notes)
# Now we are cleaning it up.
# Removing the hashes from the dates and titles.
for note in notes:
date = note[0][2:]
if note[2].startswith("### "):
note_title = note.pop(2)[3:]
copy = " ".join(note[1:])
def add_to_payload(date, note_title, copy, company_name):
payload = {
"records": [
{
"Author": "nrasmussen@gainsight.com",
"ContextName": company_name,
"TypeName": "Meeting",
"ExternalId": "WHAT IS THIS?",
"Subject": note_title,
"Notes": copy,
"ActivityDate": date,
"companyName": "AAR Corp Hardware Abscoa Division",
"internalAttendees": ["Norm Rasmussen"],
"externalAttendees": [""],
},
]
}
send_to_gs(payload)
def send_to_gs(payload):
url = "https://gongnxt.gainsightcloud.com/v1/ant/es/activity/bulk"
json = payload
headers = {
"Content Type": "JSON",
"Accesskey": APIKEY,
}
response = requests.post(url=url, headers=headers, json=payload)
if __name__ == "__main__":
get_files()