-
-
Save mynameiskreang/d3fcd5c1fcbcf8b5ab08509955a25706 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function searchMyZone() { | |
try { | |
const threads = GmailApp.search('label:"myzone"'); | |
const labelMyZone = GmailApp.getUserLabelByName('myzone'); | |
for (const thread of threads) { | |
thread.removeLabel(labelMyZone); | |
const messages = thread.getMessages() | |
for (const message of messages) { | |
var body = message.getBody(); | |
body = body.replace("<!-- -->", ""); | |
var content = body.substring( | |
body.indexOf("<body ") + 0, | |
body.lastIndexOf("</body>") + 7 | |
); | |
var text = []; | |
const $ = Cheerio.load(content); | |
$('span[style*="font-family: \'Trebuchet MS\', sans-serif; color: #000000;"]').each(function(i, elm) { | |
text[i] = trim($(this).text()); | |
}); | |
var img; | |
$('img').each(function(i, elm) { | |
if (i==2){ | |
img = $(this).attr('src'); | |
} | |
}); | |
var calendar = CalendarApp.getCalendarById('your_google_calendar_id'); | |
const title = `${text[3]}mins ${text[5]}cals`; | |
var event = calendar.createAllDayEvent(title,new Date(trim(text[1])), | |
{description: `Workout Summary\r\nMinutes ${text[3]}\r\nAvg. Effort ${text[4]}\r\nCalories ${text[5]}\r\nAvg. HR ${text[6]}\r\n${img}`}); | |
} | |
} | |
}catch(err){ | |
console.log(err); | |
} | |
} | |
function trim(input){ | |
input = input.replace(/\n/g,''); | |
input = input.replace(/^\s+|\s+$/g,''); | |
var result = input.match(/[0-9][0-9]:[0-9][0-9] (PM|AM)/g); | |
if (result != null) { | |
input = result.join(' - '); | |
} | |
return input; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment