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
// SET UP ON SHEETS | |
function onOpen(e) { | |
var ui = SpreadsheetApp.getUi(); | |
ui.createMenu('Get Txns').addItem('Populate Sheets', 'processTxnEmails').addToUi(); | |
} | |
// FILTERING EMAILS... |
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
var timeframe = 'newer_than:1h'; | |
var filter = timeframe + " AND subject:GeNS transaction Alert AND -label:scripting-emails"; |
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 labelMessagesAsDone(messages) { | |
var labelName = 'scripting-emails'; | |
Logger.log('Processing labels...'); | |
var mylabel = GmailApp.getUserLabelByName(labelName); | |
if (!mylabel) { | |
mylabel = GmailApp.createLabel(labelName); | |
Logger.log("Label doesn't exist, creating new " + labelName); | |
} |
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
// SAVE DATA TO GOOGLE SHEETS | |
function saveToSheet(txnData){ | |
// Replace url with your own url link. | |
var expenseSpreadsheet = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1VZBkiqoTmcnWcxvNCEgHwMLhy_sBof4Cbd0gmKvkxOk/edit#gid=0"); | |
var dataSheet = expenseSpreadsheet.getSheetByName("Data"); | |
Logger.log('Populating spreadsheet...'); | |
for (var txn = 0; txn < txnData.length; txn++) { |
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
// Program Entry Point. | |
function doGet() { | |
// return displayEmails(); | |
return displayParsedData(); | |
} |
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
// PARSING EMAIL MESSAGES... | |
function parseMessageBody(messages) { | |
... | |
} | |
// DISPLAY PARSED TRANSACTION DATA | |
function displayParsedData() { |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<base target="_top"> | |
<title>Data parsed from emails</title> | |
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css"> | |
</head> | |
<body style="padding:3em;"> | |
<h2>Parsed data from Messages</h2> | |
<table style="width:800px"> |
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
// PARSING EMAIL MESSAGES... | |
function parseMessageBody(messages) { | |
var txnData = []; | |
for (var m = 0; m < messages.length; m++) { | |
var text = messages[m].getPlainBody(); | |
Logger.log(m); |
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 doGet() { | |
return displayEmails(); | |
} |
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
// FILTERING EMAILS... | |
function getBankEmails() { | |
// This function searches for messages from emails having subject containing | |
// “GeNS transaction Alert …” | |
var filter = "subject:GeNS transaction Alert"; | |
var threads = GmailApp.search(filter, 0, 10); | |
var messages = []; | |
for (var x in threads) { |