-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
43 lines (36 loc) · 1023 Bytes
/
Copy pathindex.ts
File metadata and controls
43 lines (36 loc) · 1023 Bytes
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
import { env } from "node:process";
import dotenv from "dotenv";
import writeData from "./writeData";
import fetchSheet from "./fetchSheet";
import prepData from "./prepData";
dotenv.config();
const fetchLirrData = async () => {
const response = await fetch(
"https://backend-unified.mylirr.org/locations?geometry=NONE&railroad=LIRR",
{
headers: { "Accept-Version": "3.0" },
}
);
return await response.json();
};
const updateSheet = async (spreadsheetId: string) => {
const [sheetData, lirrData] = await Promise.all([
fetchSheet(spreadsheetId),
fetchLirrData(),
]);
const updatedData = prepData({ sheetData, lirrData });
await writeData(updatedData, spreadsheetId);
console.info("Spreadsheet updated successfully");
};
const main = async () => {
try {
await updateSheet(env.G_SHEET_ID as string);
} catch (e) {
console.error(e);
throw new Error(`Failed to update spreadsheet\n\n${e}`);
}
};
main().catch((e) => {
console.error(e);
process.exit(1);
});