-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.gs
64 lines (53 loc) · 1.67 KB
/
Main.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// ****** SETUP ******
// 1. change the string assignment of the EMAIL variable to your phone number email address.
// Use the guide below to figure out the proper email for your number:
// AT&T: '+###########@txt.att.net'
// T-Mobile: '+###########@tmomail.net'
// Verizon: '+###########@vtext.com'
// Sprint: '+###########@messaging.sprintpcs.com'
// 2. Run the init() function and agree to the permissions
// ****** ALL DONE ******
var EMAIL = '<YOUR PHONE NUMBER EMAIL ADDRESS>'
function init(){
var props = PropertiesService.getUserProperties();
var triggerId = props.getProperty('triggerId')
if(triggerId &&
ScriptApp.getProjectTriggers().some(function(trigger){
return trigger.getUniqueId() == triggerId;
})){
Logger.log('Trigger already set up')
return;
}
var triggerId = ScriptApp.newTrigger("check")
.timeBased()
.everyMinutes(1)
.create()
.getUniqueId();
props.setProperty('triggerId', triggerId);
Logger.log('Trigger set up');
}
function check(){
var now = Date.now();
var props = PropertiesService.getUserProperties();
var lastUpdate = Number(props.getProperty('lastUpdate') || now-(24*60*60*1000))
try{
eventCodes = checkEmail(lastUpdate)
}
catch(f){
console.error(f)
MailApp.sendEmail(EMAIL, 'ERROR', f.message)
return;
}
eventCodes.forEach(function(eventCode){
try{
var eventData = getEventObject(eventCode)
var event = scheduleEvent(eventData)
MailApp.sendEmail(EMAIL, event.getTitle(), event.getStartTime().toString())
}
catch(f){
console.error(f)
MailApp.sendEmail(EMAIL, 'ERROR', f.message)
}
});
props.setProperty('lastUpdate', now-(10*60*1000))
}