-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstopGcalSpam.gs
More file actions
53 lines (46 loc) · 1.74 KB
/
stopGcalSpam.gs
File metadata and controls
53 lines (46 loc) · 1.74 KB
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
//Based on Google's quick start guid:
//https://developers.google.com/calendar/quickstart/apps-script
//And a function by (@Anton Dementiev) from StackOverflow:
//https://stackoverflow.com/questions/49794213/how-to-delete-an-event-with-google-apps-script-and-sending-an-email/49795562#49795562
function listUpcomingEvents() {
var calendarId = 'primary';
var optionalArgs = {
timeMin: (new Date()).toISOString(),
showDeleted: false,
singleEvents: true,
maxResults: 1000,
orderBy: 'startTime'
};
var badStrings = ["ВАМ ДОСТУПЕН ДЕНЕЖНЫЙ ПЕРЕВОД","ДЕНЕЖНЫЙ","НАЧИСЛЕНИЕ","СРЕДСТВ"];
var response = Calendar.Events.list(calendarId, optionalArgs);
var events = response.items;
if (events.length > 0) {
for (i = 0; i < events.length ; i++) {
var event = events[i];
for (badString in badStrings) {
if(event.summary.indexOf(badStrings[badString]) > 0 ) {
//Delete the event
deleteEvent(event.id);
}
}
var when = event.start.dateTime;
if (!when) {
when = event.start.date;
}
}
} else {
Logger.log('No upcoming events found.');
}
}
function deleteEvent(eventId) {
var baseUrl = "https://www.googleapis.com/calendar/v3/calendars/{calendarId}/events/{eventId}?sendNotifications=false";
var calendarId = CalendarApp.getDefaultCalendar().getId();
var url = baseUrl.replace("{calendarId}", calendarId).replace("{eventId}", eventId);
var options = {
"method": "DELETE",
"headers": {"Authorization":"Bearer " + ScriptApp.getOAuthToken()},
"muteHttpExceptions": true
};
var res = UrlFetchApp.fetch(url, options).getContentText();
Logger.log(res);
}