maandag 20 april 2020

Importing a (part of a) PDF schedule into Google Calendar with #GoogleAppsScript


Twice a year I get a schedule like the schedule above. It is part of a PDF document. Every row is a 'shift' in which asylum applications are processed at Airport Schiphol in the so called border procedure. In every 'shift' there are 5 days for a lawyer.

How to get all these days into my calendar.

I copy the schedule and paste it into a mail to myself with $$$$$ in the subject.

An then:

function shiftToCalendar(){
  
  var kindOfShiftDays = [[0,"dagmineen"],[1,"a&c eerste gehoor"],[2,"a&c nader gehoor"],[3,"zienswijze"],[4,"beschikking"]]
  var threads = GmailApp.search("newer_than:1d from:me subject:$$$$$");
  var message = threads[0].getMessages()[0];
  
  if(message){
    
  var shifts = message.getBody().split(/A11608/g); 
    
    for(var d=1;d<shifts.length;d++){
      
      var shift = shifts[d];
      
      if(/AC /.test(dienst) && shift.match(/\d{1,2}\-\d{1,2}\-\d{4}/gm) !== null){
            
        var shiftDays = shift.match(/\d{1,2}\-\d{1,2}\-\d{4}/gm);
        
            for(var e=0;e<shiftDays.length;e++){
             
              var hlpShiftDay = shiftDays[e].split(/\-/g);
              var shiftDay = new Date(hlpShiftDay[2],hlpShiftDay[1]-1,hlpShiftDay[0]); 
              
              for(var f=0;f<kindOfShiftDays.length;f++){
                  
                if(kindOfShiftDays[f][0] == e){var what = kindOfShiftDays[f][1]}
                 
                  }
            
              CalendarApp.getCalendarById(MIJNKALENDER()).createAllDayEvent(what,shiftDay).setColor(d);
            
            }
        }
    }  
  
    message.moveToTrash();
  }  
}

Geen opmerkingen:

Een reactie posten