Posts

Showing posts with the label Google Apps Script

IT Notes : Using Google Apps Script to export Google Calendar events to Google Sheet

Image
Steps : 1.      Open Google Calendar and export events to Google sheet  2.      Create a 5 columns Google Sheet with sheet name " Feb 2023"   : Date, Start time, End time, Time slot hours, Total hours for the week 3.      Apply the following format for columns : Date : date (dd/mm/yyyy) Start time : time (hh:mm:ss) End time : time (hh:mm:ss) Time slot hours : number 4.      Create a Google App Script using the Google Calendar API Service : function MonthSchedule(){   var ss = SpreadsheetApp.getActiveSpreadsheet();   var sheet = ss.getSheetByName("Feb 2023");   var cal = CalendarApp.getCalendarById("xxxxx@gmail.com");   //用 getEvents(startTime, endTime) 來取得資料, e.g. Feb 2023   var events = cal.getEvents(new Date("2/01/2023 12:00 AM"), new Date("2/28/2023 11:59 PM"));   for(var i = 0;i<events.length;i++){     var title = events[i].getTitle();     ...

IT Notes : Using Google Apps Script to update Google Calendar events from Google Sheet

Image
Steps to update Google Calendar from Google spreadsheet     1. Choose  Calendar for update.   2. Access the Calendar using Google Calendar ID     • var cal = CalendarApp.getCalendarById("xxxxx@gmail.com");   3. Identify the  spreadsheet  containing Calendar event data, e.g.  sheet name =  GetEvents     • var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("GetEvents");    4. Specifiy cells that we want to grab data from     • var dataRange = mySpreadsheet.getRange("B2:C46");     5. Import data from the spreadsheet   var data = dataRange.getValues();     6. Create Calendar events from  spreadsheet  with sheet name =  GetEvents     •  myCalendar.createEvent(myTitle, myStartTime, myEndTime, {location: myLocation, description: myDescription}); Create a Google Sheet with 5 columns  Name of Event, Start date/time, End date/ti...

IT筆記:使用Google Apps Script 監察網站狀況

Image
參考了這個網站( Spreadsheet Dev )的文章,使用 Google Sheet 和改動了一些 Google Apps Script程式碼,用來監察網站的服務是否正常。 步驟如下 :  創建一個 Google 表格電子表格來跟踪網站隨時間的狀態 登錄谷歌賬戶並在瀏覽器輸入 https://spreadsheet.new 來創建新的 Google Sheet 將新的試算表命名為 Web Monitor 並加上四個欄位 "Url " , "Date", "Status", "Load time" 在Google試算表菜單選擇「擴充功能」,Apps Script。 重新命名專案命名為 web monitor 20221216,並創建兩個分別命名為 checkWebsiteStatus 及 SetTimeTrigger的 Google Script。 輸入需要監察網站的地址url及接收電郵的帳戶。 function checkWebsiteStatus() {   let url = " https://www.abovethcloud.com/ ";   // Record time so we can track how long the website   // takes to load.   let start = new Date();   let response = UrlFetchApp.fetch(url, {muteHttpExceptions: true});   let end = new Date();   let responseCode = response.getResponseCode();   let loadTimeMs = end - start;   // Record a log of the website's status to the spreadsheet.   SpreadsheetApp.getActive().getSheetByName("Data").appendRow([url, start, responseCode, loadTimeMs]);   // Se...