diff --git a/.github/workflows/deploy-google-script.yml b/.github/workflows/deploy-google-script.yml new file mode 100644 index 0000000..89ae09b --- /dev/null +++ b/.github/workflows/deploy-google-script.yml @@ -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' \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..842e376 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.clasp.json \ No newline at end of file diff --git a/Code.js b/Code.js new file mode 100644 index 0000000..10f27da --- /dev/null +++ b/Code.js @@ -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; + } + } + } + } +} \ No newline at end of file diff --git a/appsscript.json b/appsscript.json new file mode 100644 index 0000000..1f95d0b --- /dev/null +++ b/appsscript.json @@ -0,0 +1,7 @@ +{ + "timeZone": "Europe/Brussels", + "dependencies": { + }, + "exceptionLogging": "STACKDRIVER", + "runtimeVersion": "V8" +} \ No newline at end of file