Slots

mail@pastecode.io avatar
unknown
javascript
2 years ago
1.1 kB
2
Indexable
Never
function pullData() {  
  let slots = getSlots();  
  if (!slots.length) {  
    return;  
  }  
  let subject = "Available IND slots:" + slots;  
  let message = "slots: " + slots;  
  message += "\nLink: https://oap.ind.nl/oap/en/#/DOC";  
  Logger.log(message);  
  
  MailApp.sendEmail("email@email", subject, message);
}  
  
function getSlots(){  
    let placeKey = "AM"; // Amsterdam
    let persons = 1;  
    let productKey = "DOC"; // BIO, DOC
    let response = UrlFetchApp.fetch("https://oap.ind.nl/oap/api/desks/"+placeKey+"/slots/?productKey="+productKey+"&persons="+persons);  
    let responseText = response.getContentText().replace(")]}',", '');  
    let parsedJson = JSON.parse(responseText);  
    if (parsedJson["status"] != "OK"){  
        Logger.log(JSON.stringify(parsedJson))  
        return  
    }  
  
    let dates = [];  
    for (let d of parsedJson["data"]) {  
        dates.push(d["date"]);  
    }  
    let MAX_DATE = '2023-08-01';  
    let uDates = Array.from(new Set(dates));  
    uDates.sort();  
    Logger.log(uDates);  
    return uDates.filter(d => new Date(d) < new Date(MAX_DATE))  
}