Skip to content

Commit

Permalink
trying clasp
Browse files Browse the repository at this point in the history
  • Loading branch information
Deniz Gökçin committed Aug 10, 2024
0 parents commit 5509200
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/deploy-google-script.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Deploy Google Script

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Deploy Google Apps Script
uses: Mayu-mic/google-apps-script-action@v1
with:
clasprc: ${{ secrets.CLASPRC_JSON }}
scriptId: ${{ secrets.SCRIPT_ID }}
command: 'push'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.clasp.json
117 changes: 117 additions & 0 deletions Code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// TEST
// Emoji map for event types
const emojiMap = {
'interview': '🎙️',
'flight': '🛫',
'journey': '🚆',
'stay': '🏠',
'reservation': '🏨',
'holy shred': '💪',
'holy ride': '🚵',
'meeting': '🤝',
'catch-up': '☕',
'video call': '📹',
'sosyal aktivite': '🎉',
'paris 2024': '🏅',
'randevu': '📅',
'appointment': '📅',
'tamir': '🛠️',
'repair': '🛠️',
};

function ColorEvents() {
const isDevelopment = false; // Development flag
var today = new Date();
var nextmonth = new Date();

nextmonth.setDate(nextmonth.getDate() + 31);

var startDate = today;
var endDate = nextmonth;

// Development mode date range override
if (isDevelopment) {
startDate = new Date('2023-08-01'); // YYYY-MM-DD
endDate = new Date('2024-08-31'); // YYYY-MM-DD
}

Logger.log("Date range: " + startDate + " to " + endDate);

Logger.log(today + " " + nextmonth);

var calendars = CalendarApp.getCalendarsByName("main");
Logger.log("found number of calendars: " + calendars.length);

for (var i = 0; i < calendars.length; i++) {
Logger.log("Calendar: " + calendars[i].getName());
var calendar = calendars[i];
var events = calendar.getEvents(startDate, endDate);
for (var j = 0; j < events.length; j++) {
var e = events[j];
var title = e.getTitle();
var originalTitle = title;
var color = null;

// Check for matching event types and add emojis
for (const [key, emoji] of Object.entries(emojiMap)) {
const regex = new RegExp(key, 'i'); // Case-insensitive match
if (regex.test(title)) {
if (!title.startsWith(emoji)) {
title = `${emoji} ${title}`;
}
break; // Stop after first match to avoid multiple emojis
}
}

// Set colors (commented out for now)
if (originalTitle.includes("interview")) {
color = CalendarApp.EventColor.YELLOW;
Logger.log("Title: " + title + " - Color to print: YELLOW");
} else if (originalTitle.includes("flight") || originalTitle.includes("journey")) {
color = CalendarApp.EventColor.ORANGE;
Logger.log("Title: " + title + " - Color to print: ORANGE");
} else if (originalTitle.includes("stay") || originalTitle.includes("reservation")) {
color = CalendarApp.EventColor.PALE_BLUE;
Logger.log("Title: " + title + " - Color to print: PALE_BLUE");
} else if (originalTitle.includes("holy shred") || originalTitle.includes("holy ride")) {
color = CalendarApp.EventColor.RED;
Logger.log("Title: " + title + " - Color to print: RED");
} else if (originalTitle.startsWith("🤝 Meeting") || originalTitle.includes("catch-up")) {
color = CalendarApp.EventColor.MAUVE;
Logger.log("Title: " + title + " - Color to print: MAUVE");
} else if (originalTitle.includes("sosyal aktivite")) {
color = CalendarApp.EventColor.PALE_GREEN;
Logger.log("Title: " + title + " - Color to print: PALE_GREEN");
} else if (originalTitle.includes("paris 2024")) {
color = CalendarApp.EventColor.BLUE;
Logger.log("Title: " + title + " - Color to print: BLUE");
} else if (originalTitle.includes("randevu") || originalTitle.includes("appointment")) {
color = CalendarApp.EventColor.GRAY;
Logger.log("Title: " + title + " - Color to print: GRAY");
}
else if (originalTitle.includes("tamir") || originalTitle.includes("repair")) {
color = CalendarApp.EventColor.GREEN;
Logger.log("Title: " + title + " - Color to print: GREEN");
}

// Update event title and color if changed
if (title !== originalTitle || color) {
try {
if (!isDevelopment) {
if (title !== originalTitle) {
e.setTitle(title);
Logger.log("Updated title: " + title);
}
if (color) {
e.setColor(color);
}
}
} catch (error) {
Logger.log("Error updating event: " + error.toString() + " - Title: " + originalTitle);
// Optionally, you can continue with the next event
continue;
}
}
}
}
}
7 changes: 7 additions & 0 deletions appsscript.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"timeZone": "Europe/Brussels",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}

0 comments on commit 5509200

Please sign in to comment.