-
Notifications
You must be signed in to change notification settings - Fork 1
/
goog_app_script.js
57 lines (43 loc) · 2.33 KB
/
goog_app_script.js
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
function main() {
var today = Utilities.formatDate(new Date(), "CST", "yyyy-MM-dd"); //make sure you set your timezone
var labelCount = GmailApp.getMessagesForThreads(GmailApp.getUserLabelByName("somelabel").getThreads()).length;
var unreadCount = GmailApp.getInboxUnreadCount();
var starredCount = GmailApp.getMessagesForThreads(GmailApp.getStarredThreads()).length;
var sentTodayMessages = GmailApp.getMessagesForThreads(GmailApp.search("from:me after:" + today));
var receivedTodayMessages = GmailApp.getMessagesForThreads(GmailApp.search("from:(!me) after:" + today));
var receivedTodayCount = 0;
var sentTodayCount = 0;
for (var i = 0 ; i < receivedTodayMessages.length; i++) {
for (var j = 0; j < receivedTodayMessages[i].length; j++) {
var msgDate = Utilities.formatDate(receivedTodayMessages[i][j].getDate(), "CST", "yyyy-MM-dd");
if (!(receivedTodayMessages[i][j].getFrom().match('[email protected]')) && (msgDate == today)) receivedTodayCount ++;
}
}
for (var i = 0 ; i < sentTodayMessages.length; i++) {
for (var j = 0; j < sentTodayMessages[i].length; j++) {
var msgDate = Utilities.formatDate(sentTodayMessages[i][j].getDate(), "CST", "yyyy-MM-dd");
if (sentTodayMessages[i][j].getFrom().match('[email protected]') && msgDate == today) sentTodayCount ++;
}
}
var unamepass ='API_KEY:ignore';
var digest = Utilities.base64Encode(unamepass);
var digestfull = "Basic "+digest;
var httpheaders = {
"Authorization" : digestfull,
"Accept" : "application/json"
};
var options = {
"method" : "post",
"headers" : httpheaders
};
options.payload = '{"value":' + sentTodayCount + '}';
var response = UrlFetchApp.fetch("https://push.ducksboard.com/values/ID/", options);
options.payload = '{"value":' + receivedTodayCount + '}';
response = UrlFetchApp.fetch("https://push.ducksboard.com/values/ID/", options);
options.payload = '{"value":' + unreadCount + '}';
response = UrlFetchApp.fetch("https://push.ducksboard.com/values/ID/", options);
options.payload = '{"value":' + labelCount + '}';
response = UrlFetchApp.fetch("https://push.ducksboard.com/values/ID/", options);
options.payload = '{"value":' + starredCount + '}';
response = UrlFetchApp.fetch("https://push.ducksboard.com/values/ID/", options);
}