Skip to content

Commit

Permalink
Use appending
Browse files Browse the repository at this point in the history
  • Loading branch information
francojreyes committed Oct 13, 2023
1 parent 1d23762 commit e5a9e04
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/parseBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const parseName = (rawName: string): ParsedName => {
}
}

console.warn(`Warning: No pattern found for "${rawName}"`);
console.warn(`Warning: No pattern found to parse booking name "${rawName}"`);
return { bookingType: 'MISC', name: 'Misc.' }
}

Expand Down
20 changes: 15 additions & 5 deletions src/runScraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ const runScrapeJob = async () => {
const parsedBookings = bookings.map(parseBooking).flat();
parsedBookings.sort((a, b) => a.start.getTime() - b.start.getTime());

return { buildings: filteredBuildings, rooms, bookings: parsedBookings };
}

const runScraper = async () => {
console.time('Scraping');
const { buildings, rooms, bookings } = await runScrapeJob();
console.timeEnd('Scraping');

await axios.post(
`${HASURAGRES_URL}/insert`,
{
Expand All @@ -29,7 +37,7 @@ const runScrapeJob = async () => {
sql_down: fs.readFileSync("./sql/buildings/down.sql", "utf8"),
columns: ["id", "name", "lat", "long", "aliases"],
},
payload: filteredBuildings
payload: buildings
},
{
headers: {
Expand All @@ -46,6 +54,8 @@ const runScrapeJob = async () => {
columns: ["abbr", "name", "id", "usage", "capacity", "school", "buildingId"],
sql_up: fs.readFileSync("./sql/rooms/up.sql", "utf8"),
sql_down: fs.readFileSync("./sql/rooms/down.sql", "utf8"),
sql_execute: "DELETE FROM Rooms WHERE \"usage\" = 'LIBRARY';",
write_mode: 'append'
},
payload: rooms
},
Expand All @@ -64,17 +74,17 @@ const runScrapeJob = async () => {
columns: ["bookingType", "name", "roomId", "start", "end"],
sql_up: fs.readFileSync("./sql/bookings/up.sql", "utf8"),
sql_down: fs.readFileSync("./sql/bookings/down.sql", "utf8"),
sql_execute: "DELETE FROM Bookings WHERE \"bookingType\" = 'LIBRARY';",
write_mode: 'append'
},
payload: parsedBookings
payload: bookings
},
{
headers: {
"Content-Type": "application/json"
}
}
);

}

console.time('Scraping');
runScrapeJob().then(() => console.timeEnd('Scraping'));
runScraper();

0 comments on commit e5a9e04

Please sign in to comment.