Repository navigation
Expand file tree
/
Copy pathindex.ts
More file actions
54 lines (42 loc) · 1.57 KB
/
Copy pathindex.ts
File metadata and controls
54 lines (42 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import * as fs from 'fs';
import * as rm from 'typed-rest-client/RestClient';
import notifier = require('node-notifier');
import { TurboVaxRootObject } from './types';
let rest: rm.RestClient = new rm.RestClient('rest-samples');
let eTagTurbo = fs.readFileSync('turboVaxEtag.txt').toString();
async function runTurboVax() {
let res: rm.IRestResponse<TurboVaxRootObject>;
try {
res = await rest.get<TurboVaxRootObject>('https://api.turbovax.info/dashboard',
560A
{
additionalHeaders: {
"if-none-match": eTagTurbo,
},
});
} catch (error) {
console.log(error);
return;
}
console.log("TurboTax " + res.statusCode);
console.log(`Current ETag: ${eTagTurbo}`);
eTagTurbo = (res.headers as any)['etag'];
console.log(`New ETag: ${eTagTurbo}`);
fs.writeFileSync('turboVaxEtag.txt', eTagTurbo);
const lastUpdated = res.result?.last_updated_at;
console.log(`Last Updated: ${lastUpdated}`)
const availableLocations = res.result?.locations.filter(
loc => loc.appointments.count > 0
&& ["Queens", "Brooklyn", "Manhattan"].includes(loc.area)
&& loc.id !== "York College (Queens residents only)"
// && loc.available
// && loc.active
);
if (!availableLocations?.length) {
return;
}
notifier.notify({
title: "TurboTax: Found Appointment",
message: JSON.stringify(availableLocations, null, 2)
})
console.log(JSON.stringify(availableLocations, null, 2));
}
setInterval(runTurboVax, 5000, runTurboVax)