-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup.js
69 lines (62 loc) · 1.72 KB
/
cleanup.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
58
59
60
61
62
63
64
65
66
67
68
69
const { google } = require("googleapis");
const credentials = require("./credentials");
const data = require("/Users/mkruk/Desktop/northport_omena_calendar_backup.json");
const calendarId = "[email protected]";
const SCOPES = [
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/calendar.events",
];
const keepIds = [
"l18bqbppkuljcv6vns7pbehb28",
"rc44mfd0ij6sqq5pbnt4uh0nac",
"u04aqe05bt9e8ado5h9k506mag",
"58km8oteh97mt0i4n5f1vjd6e4",
"g6uhoqchf9pnq4uiiuh8et5ovc",
"eo46oo02io1qivplperu0713qg",
"87prh0vj2glnkc6ep4ekcftbhs",
"k6i4sgqm9cih6ut6uah7djfrbk",
"sjla649sgph8qnca69dh1hriag",
"3tm111e508jhdi9ehqn1jgd2lc",
"g6uhoqchf9pnq4uiiuh8et5ovc",
];
async function main() {
console.log(calendarId);
const auth = await google.auth.getClient({
credentials,
scopes: SCOPES,
});
const cal = google.calendar({ version: "v3", auth });
// const toDisplay = data.items.filter((event) => keepIds.includes(event.id));
// for (const event of toDisplay) {
// await cal.events.patch({
// calendarId,
// eventId: event.id,
// resource: {
// status: "confirmed",
// },
// });
// }
const toDelete = data.items.filter(
(event) =>
!keepIds.includes(event.recurringEventId) && !keepIds.includes(event.id)
);
for (const event of toDelete) {
try {
console.log(event);
if (event.visibility !== "private") {
await cal.events.patch({
calendarId,
eventId: event.id,
resource: {
status: "cancelled",
visibility: "private",
},
});
}
} catch (err) {
console.log(err);
}
}
process.exit(0);
}
main();