From 8dfe680b7500e491844bb0db1d6de7ec5ad3adb2 Mon Sep 17 00:00:00 2001 From: alex ghose Date: Tue, 23 Mar 2021 09:01:36 -0400 Subject: [PATCH 1/5] getting closer to a fix! --- index.js | 13 ++++++++++--- topic.json | 3 --- 2 files changed, 10 insertions(+), 6 deletions(-) delete mode 100644 topic.json diff --git a/index.js b/index.js index 70328ad..6b2c3ee 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,8 @@ const { GoogleSpreadsheet } = require("google-spreadsheet"); const creds = require("./config/zoom-recording-tracker-6a8bd724ca99.json"); /* DIRTY REGEX FOR PULLING THE URL AND PASSWORD */ -const regex = /(?<=share this recording with viewers\:\n)(.*)|(?<=Passcode\:\n)(.*)/g; +//const regex = /(?<=share this recording with viewers\:\n[<]a href=["])(.*)|(?<=Passcode\:\n)(.*)/g; +const regex = /(share this recording with viewers(.|\n)*)">((.|\n)*)(<\/a>)(.|\n)*Passcode: (.*)/g; /* ----------------------------- */ // readXML.loadDoc(); @@ -45,7 +46,11 @@ mailListener.on("error", function (err) { mailListener.on("mail", async function (mail, seqno, attributes) { let newMessage = ""; if (mail.from[0].address == conf.email && mail.subject == conf.catchSubject) { - let parsedMessage = mail.text.match(regex); + console.log("mail:", mail) + mail.html = mail.html.replace(//g, '') + console.log("***mail.html with linebreaks replaced***", mail.html) + let parsedMessage = mail.html.match(regex); + console.log("parsed message:", parsedMessage) if (parsedMessage && parsedMessage.length === 2){ try { let sheet = await sheetsConnect(); @@ -54,7 +59,9 @@ mailListener.on("mail", async function (mail, seqno, attributes) { console.log(err); } - } + } else { + console.log("FAILED TO MATCH REGEX") + } } }); diff --git a/topic.json b/topic.json deleted file mode 100644 index 3a05d50..0000000 --- a/topic.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "TOPIC": "This Lectures Topic" -} \ No newline at end of file From 3b7954c7db3afb6dad9c0728c2f41ad26f9b390c Mon Sep 17 00:00:00 2001 From: alex ghose Date: Tue, 30 Mar 2021 20:19:24 -0400 Subject: [PATCH 2/5] fix config file location --- index.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 6b2c3ee..f8e632d 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,7 @@ const creds = require("./config/zoom-recording-tracker-6a8bd724ca99.json"); /* DIRTY REGEX FOR PULLING THE URL AND PASSWORD */ //const regex = /(?<=share this recording with viewers\:\n[<]a href=["])(.*)|(?<=Passcode\:\n)(.*)/g; -const regex = /(share this recording with viewers(.|\n)*)">((.|\n)*)(<\/a>)(.|\n)*Passcode: (.*)/g; +const regex = /share this recording with viewers((.|\n)*)">((.|\n)*)(<\/a>)((.|\n)*)Passcode: (.*)/g; /* ----------------------------- */ // readXML.loadDoc(); @@ -49,12 +49,17 @@ mailListener.on("mail", async function (mail, seqno, attributes) { console.log("mail:", mail) mail.html = mail.html.replace(//g, '') console.log("***mail.html with linebreaks replaced***", mail.html) - let parsedMessage = mail.html.match(regex); - console.log("parsed message:", parsedMessage) - if (parsedMessage && parsedMessage.length === 2){ + // matchAll gives you regex groups, and then we convert to array:q + let parsedMessage = mail.html.matchAll(regex); + console.log("parsed message:", JSON.stringify(parsedMessage)) + parsedMessage = [...parsedMessage]; // convert to array + console.log("parsed message array:", parsedMessage) + if (parsedMessage && parsedMessage[0].length > 8){ try { let sheet = await sheetsConnect(); - await updateRow(sheet, parsedMessage); + let password = parsedMessage[0][8]; + let url = parsedMessage[0][3]; + await updateRow(sheet, password, url); } catch (err) { console.log(err); } @@ -80,14 +85,14 @@ function firstEmptyRow(sheet) { /* using first empty row, populate with values passed from imap checker */ -async function updateRow(sheet, parsedMessage, topic="UPDATE TOPIC") { +async function updateRow(sheet, password, url, topic="UPDATE TOPIC") { try { await sheet.loadCells("A:D"); let newRow = firstEmptyRow(sheet); sheet.getCell(newRow, sheetParams.dateCol).value = new Date().getDateForHTML(); - sheet.getCell(newRow, 1).value = require('./topic.json').TOPIC; - sheet.getCell(newRow, sheetParams.passCol).value = parsedMessage[1]; - sheet.getCell(newRow, sheetParams.urlCol).value = parsedMessage[0]; + sheet.getCell(newRow, 1).value = require('./config/topic.json').TOPIC; + sheet.getCell(newRow, sheetParams.passCol).value = password; + sheet.getCell(newRow, sheetParams.urlCol).value = url; sheet.saveUpdatedCells(); } catch (err) { console.log(err); From 0b98ee20e2d4a5ce3a1c3e699703d766bd4ffc01 Mon Sep 17 00:00:00 2001 From: alex ghose Date: Tue, 30 Mar 2021 20:34:07 -0400 Subject: [PATCH 3/5] ignore first 5 rows --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index f8e632d..071dabb 100644 --- a/index.js +++ b/index.js @@ -75,7 +75,7 @@ mailListener.on("mail", async function (mail, seqno, attributes) { start = header column position (i.e. "URL" ) */ function firstEmptyRow(sheet) { - for (let i = sheetParams.headerRow; i < sheet.gridProperties.rowCount; i++) { + for (let i = 5; i < sheet.gridProperties.rowCount; i++) { let thisCell = sheet.getCell(i, sheetParams.urlCol); if (thisCell.value === null) { return i; From c51ba109ba5b0d1f69d576d2154b8ae68d89f0d9 Mon Sep 17 00:00:00 2001 From: Alexander G Date: Tue, 30 Mar 2021 21:05:35 -0400 Subject: [PATCH 4/5] change utc date to local time zone date --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 071dabb..cf4de5e 100644 --- a/index.js +++ b/index.js @@ -112,6 +112,6 @@ async function sheetsConnect() { Date.prototype.getDateForHTML = function () { return `${this.getUTCFullYear()}/${(this.getUTCMonth() + 1) .toString() - .padStart(2, "0")}/${this.getUTCDate().toString().padStart(2, "0")}`; + .padStart(2, "0")}/${this.getDate().toString().padStart(2, "0")}`; }; From 5616ff4fb442036cfa1f23b84c760e96acc6abf3 Mon Sep 17 00:00:00 2001 From: Alexander G Date: Tue, 30 Mar 2021 21:14:53 -0400 Subject: [PATCH 5/5] update date to include the day of the week --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index cf4de5e..c3c0485 100644 --- a/index.js +++ b/index.js @@ -110,7 +110,7 @@ async function sheetsConnect() { } } Date.prototype.getDateForHTML = function () { - return `${this.getUTCFullYear()}/${(this.getUTCMonth() + 1) + return `${this.toLocaleString('en-us', {weekday: 'long' })}, ${this.getUTCFullYear()}/${(this.getUTCMonth() + 1) .toString() .padStart(2, "0")}/${this.getDate().toString().padStart(2, "0")}`; };