Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function processGoogleMeetAttendance(){
- //Change the 3 variables below.
- const driveInputFolderId = '1QVo_pr_Wo6U4zp_qODSzg0y387WPH9Yx'
- const driveProcessedFolderId = '1PSn8gXnGisV9t4xWsaPxxXhdYp0A6v1F'
- const sheetName = 'csv'
- const files = DriveApp.getFolderById(driveInputFolderId).getFilesByType(MimeType.CSV)
- console.log((files.hasNext()) ? `Found files` : `No files found in folder`)
- while (files.hasNext()){
- const file = files.next()
- console.log(`Processing: ${file.getName()}`)
- const csvString = file.getBlob().getDataAsString()
- let converted = Utilities.parseCsv(csvString)
- const date = /"(.*?)"/.exec(converted[1][1])[1]
- converted.splice(0, 4)
- converted.splice(converted.length -4,4)
- const clean = converted.map(row => {
- row.unshift(date)
- return row.map(column => {
- const noQuotes = /"(.*?)"/.exec(column)
- if (noQuotes != null){
- return noQuotes[1];
- } else {
- return column
- }
- })
- })
- const ss = SpreadsheetApp.getActiveSpreadsheet()
- const targetSheet = ss.getSheetByName(sheetName)
- targetSheet.getRange(targetSheet.getLastRow()+1,1, clean.length, clean[0].length).setValues(clean)
- file.moveTo(DriveApp.getFolderById(driveProcessedFolderId))
- console.log(`Done processing ${file.getName()} and moved to processed folder`)
- }
- }
Add Comment
Please, Sign In to add comment