Last active
September 26, 2018 14:27
-
-
Save dwaq/03b556940e56a069bb555bdaf1ab0b75 to your computer and use it in GitHub Desktop.
Automatically Plot Data from Emails https://mylifeasa.tinkerer.us/automatically-plot-data-from-emails-1f1ffab96ffb
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 menu(e) { | |
var ui = SpreadsheetApp.getUi(); | |
ui.createMenu('Macros') | |
.addItem('Parse email', 'interest') | |
.addToUi(); | |
} | |
function interest() { | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var s = ss.getActiveSheet(); | |
var threads = GmailApp.search('subject: "Dollar Bank rate watch notification*"'); | |
var a=[]; | |
for (var i = 0; i < threads.length; i++) { | |
var messages = GmailApp.getMessagesForThread(threads[i]); | |
for (var j = 0; j < messages.length; j++) { | |
a.push(parseMail(messages[j].getPlainBody(), messages[j].getDate())); | |
} | |
} | |
// start at row 3, overwrite old data | |
var nextRow=3; | |
var numRows=a.length; | |
var numCols=a[0].length; | |
s.getRange(nextRow,1,numRows,numCols).setValues(a); | |
} | |
function parseMail(body, date) { | |
// split based on newlines | |
var lines = body.split("\n"); | |
// hold lines split by spaces | |
var lines_split = []; | |
// hold important data | |
var rates = []; | |
rates.push(date); | |
for (var i = 0; i < 3; i++) | |
{ | |
lines_split[i] = lines[i+7].split(" "); | |
rates.push(lines_split[i][4]); | |
rates.push(lines_split[i][6]); | |
rates.push(lines_split[i][10]); | |
} | |
return rates; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment