Skip to content

Instantly share code, notes, and snippets.

@Dianoga
Created January 2, 2020 19:06
Show Gist options
  • Save Dianoga/b6930cbe23e86bf76b3046e59e621fbd to your computer and use it in GitHub Desktop.
Save Dianoga/b6930cbe23e86bf76b3046e59e621fbd to your computer and use it in GitHub Desktop.
Trusted Traveler Better Appointment Checker
#!/usr/bin/node
const https = require('https');
const currentAppt = '2020-05-26T09:30'; // Replace with the timestamp of your current appointment
const locationId = 6840; // Replace with the id of the location you want to check
const pushoverApiKey = '<your pushover api key>';
const pushoverUserKey = '<your pushover user key>';
const request = (url, options, data) =>
new Promise((resolve, reject) => {
const req = https.request(url, options, function(res) {
const chunks = [];
res.on('data', function(chunk) {
chunks.push(chunk);
});
res.on('end', function(chunk) {
const body = Buffer.concat(chunks);
try {
const resp = JSON.parse(body.toString());
resolve(resp);
} catch (e) {
console.error(e);
reject(e);
}
});
res.on('error', function(error) {
console.error(error);
reject(error);
});
});
if (data) req.write(data);
req.end();
});
const doTheThing = async () => {
const resp = await request(
'https://ttp.cbp.dhs.gov/schedulerapi/slots?orderBy=soonest&limit=1&locationId=${locationId}&minimum=1',
{
method: 'GET',
headers: {
'Content-Type': 'application/json'
},
maxRedirects: 20
}
);
const firstAppt = resp[0].startTimestamp;
console.log(`Current appointment: ${currentAppt}`);
console.log(`Next available appointment: ${firstAppt}`);
if (firstAppt < currentAppt) {
const pushoverParams = {
token: pushoverApiKey,
user: pushoverUserKey,
title: 'Global Entry Appointment',
message: `Better Appointment Found: ${firstAppt}`,
url: 'https://ttp.cbp.dhs.gov/dashboard',
url_title: 'TTP Login'
};
console.warn(`Better appointment found!`);
await request(
'https://api.pushover.net/1/messages.json',
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
},
JSON.stringify(pushoverParams)
);
} else {
console.log('Not better :(');
}
};
doTheThing();
@Dianoga
Copy link
Author

Dianoga commented Jan 2, 2020

The only ways I know to grab the location id:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment