Anthology CSV parse update. Backed up Supplier Prod's templates.

This commit is contained in:
Norm Rasmussen
2024-10-28 17:07:21 -04:00
parent d93059e8c0
commit 4e24d8d695
6 changed files with 43 additions and 17 deletions

View File

@ -6,9 +6,9 @@ function main() {
while (files.hasNext()) {
var file = files.next();
var getDate = new Date();
var date = Utilities.formatDate(getDate, 'America/New_York', 'MM/dd/yyyy hh');
var date = Utilities.formatDate(getDate, 'America/New_York', 'MM/dd/yyyy hh:mm');
var fileDate = file.getDateCreated();
var fileDateFormatted = Utilities.formatDate(fileDate, 'America/New_York', 'MM/dd/yyyy hh');
var fileDateFormatted = Utilities.formatDate(fileDate, 'America/New_York', 'MM/dd/yyyy hh:mm');
if (date == fileDateFormatted) {
Logger.log("Updated: "+file)
var updated_file = file.getBlob()
@ -34,10 +34,10 @@ function moveOldFiles() {
while (files.hasNext()) {
var file = files.next();
var getDate = new Date();
var date = Utilities.formatDate(getDate, 'America/New_York', 'MM/dd/yyyy hh' );
var date = Utilities.formatDate(getDate, 'America/New_York', 'MM/dd/yyyy hh:mm' );
var fileDate = file.getDateCreated();
Logger.log("FILE: "+file+", DATE UPLOADED: "+fileDate)
var fileDateFormatted = Utilities.formatDate(fileDate, 'America/New_York', 'MM/dd/yyyy hh');
var fileDateFormatted = Utilities.formatDate(fileDate, 'America/New_York', 'MM/dd/yyyy hh:mm');
if (date != fileDateFormatted) {
const destination = DriveApp.getFolderById('1cIPZCgoj8XdjMIfL75QfomJAxsy2smGT');
file.moveTo(destination);
@ -144,12 +144,9 @@ function updatedDomainsOnly(domains_to_update) {
const dom = array.shift();
const groups = array;
Logger.log("{domain_to_update : {domain :"+dom+", group_ids : "+groups+" }}")
sendWebhook({domain_to_update : { domain: dom, group_ids: groups }})
//sendWebhook({domain_to_update : { domain: dom, group_ids: groups }})
replaceOnSheet(dom, groups);
}
// MailApp.sendEmail("nrasmussen@gainsight.com",
// "Anthology has submitted a CSV",
// "Here are the domains that will be updated: "+JSON.stringify(noErrorObj)+"\n\n"+"Group Errors (they likely don't exist): "+JSON.stringify(errorList));
MailApp.sendEmail("amitd@anthology.com",
"Anthology has submitted a CSV",
"Here are the domains that will be updated: "+JSON.stringify(noErrorObj)+"\n\n"+"Group Errors (they likely don't exist): "+JSON.stringify(errorList));
@ -165,13 +162,14 @@ function replaceOnSheet(dom, groups) {
let boo = sheet.createTextFinder(dom).findNext()
if (boo != null ) {
//Logger.log("Replace on Sheet Domain: "+dom)
//Logger.log("New groups: "+groups)
Logger.log("Replace on Sheet Domain: "+dom)
Logger.log("New groups: "+groups)
group2 = []
currCell = boo.getRowIndex();
groups.forEach(item => { if (item.length > 0) { group2.push(item) }});
group2 = [group2];
//Logger.log(group2);
Logger.log(group2);
sheet.getRange(currCell, 1, 1, 100).clear();
sheet.getRange(currCell, 1).setValue(dom);
sheet.getRange(currCell, 2, 1, group2[0].length).setValues(group2)
} else {

View File

@ -1,4 +1,4 @@
const apiKey = '8ALsk8jDOlynEwn8ScMBSnG87';
const apiKey = 'ANTHOAPIKEY';
function main() {
prepareSheet();
@ -14,14 +14,15 @@ function main() {
var updated_file = file.getBlob();
var updated_blob = updated_file.getDataAsString();
var updated_data = Utilities.parseCsv(updated_blob, ',');
var full_data = Utilities.parseCsv(updated_blob, ',');
} else if (date != fileDateFormatted) {
var outdated_file = file.getBlob();
var outdated_blob = outdated_file.getDataAsString();
var outdated_data = Utilities.parseCsv(outdated_blob, ',');
}
}
fullParse(updated_data);
austinComparseData(outdated_data, updated_data)
austinComparseData(outdated_data, updated_data);
fullParse(full_data);
moveOldFiles();
}
@ -93,6 +94,7 @@ function austinComparseData(outdated_data, updated_data) {
}
function quickParse(domains_to_update) {
Logger.log("Quick Parse Item: "+domains_to_update)
for (var x = 1; x < domains_to_update.length; x++) {
var array = domains_to_update[x];
for (var i = 1; i < array.length; i++) {
@ -111,7 +113,7 @@ function quickParse(domains_to_update) {
const sendMsg = UrlFetchApp.fetch(api_url, settings);
var uuidResponse = sendMsg.getContentText();
var parseData = JSON.parse(uuidResponse)
Logger.log("Austin:"+parseData)
Logger.log("Austin Check:"+item)
var groupID = parseData['data'][0]['id']
var groupName = array.indexOf(item);
if (groupName != -1) {
@ -146,7 +148,7 @@ function fullParse(updated_data) {
const sendMsg = UrlFetchApp.fetch(api_url, settings);
var uuidResponse = sendMsg.getContentText();
var parseData = JSON.parse(uuidResponse)
Logger.log("FullParse:"+parseData)
Logger.log("Current Check:"+item)
var groupID = parseData['data'][0]['id']
var groupName = array.indexOf(item);
if (groupName != -1) {