timeout each googleApi request

This commit is contained in:
Kfir Dayan 2023-03-23 21:10:44 +02:00
parent 2daf19e30a
commit e7efa713eb
3 changed files with 28 additions and 21 deletions

View file

@ -30,12 +30,16 @@ export default class GameSource {
for (let gameBox of gameBoxs) { for (let gameBox of gameBoxs) {
const teamsPlaying = gameBox.querySelectorAll(".team-name").map((team: any) => team.text); const teamsPlaying = gameBox.querySelectorAll(".team-name").map((team: any) => team.text);
console.log("TEAMS PLAYING", teamsPlaying)
const regex = /[\r\n\s]+/g; const regex = /[\r\n\s]+/g;
const gameHeader = gameBox.querySelector(".game-header").text.replace(regex, " ").trim(); const gameHeader = gameBox.querySelector(".game-header").text.replace(regex, " ").trim();
console.log("GAME HEADER", gameHeader)
const headerSplit = gameHeader.split(","); const headerSplit = gameHeader.split(",");
console.log("HEADER SPLIT", headerSplit)
// In data, if there is no time, it means it's the last game for the calender
const lastGameForCalender = headerSplit.length < 4;
if (lastGameForCalender) break;
if (headerSplit.length < 4) break;
const gameDate = headerSplit[2].trim(); const gameDate = headerSplit[2].trim();
const gameTime = headerSplit[3].trim(); const gameTime = headerSplit[3].trim();

View file

@ -41,16 +41,18 @@ export default class GoogleCalendar {
return this.JWT_client; return this.JWT_client;
} }
updateNewEvent(upcomingEvents: GoogleCalendarEvent[]) { async updateNewEvent(upcomingEvents: GoogleCalendarEvent[]) {
setTimeout(async () => {
upcomingEvents.forEach((event: GoogleCalendarEvent) => { upcomingEvents.forEach((event: GoogleCalendarEvent) => {
console.log("UPDATE NEW EVENT", upcomingEvents) console.log("UPDATE NEW EVENT", upcomingEvents)
const options = { const options = {
auth: this.JWT_client, auth: this.JWT_client,
calendarId: this.calenderId, calendarId: this.calenderId,
resource: event, resource: event,
} }
this.calendar.events.insert(options, function (err: any, event: any) { this.calendar.events.insert(options, function (err: any, event: any) {
if (err) { if (err) {
console.log('There was an error contacting the Calendar service: ' + err); console.log('There was an error contacting the Calendar service: ' + err);
@ -60,6 +62,7 @@ export default class GoogleCalendar {
}); });
}) })
}, 3000)
} }
} }

View file

@ -32,6 +32,7 @@ class App {
const games = await this.gameSource.getGamesFromHaifa(); const games = await this.gameSource.getGamesFromHaifa();
// console.log(games)
this.googleCalendar.updateNewEvent(games); this.googleCalendar.updateNewEvent(games);
} }
} }
@ -43,4 +44,3 @@ const start = async () => {
await app.getNewGamesAndUpdateCalendar(); await app.getNewGamesAndUpdateCalendar();
} }
start(); start();
// console.log(moment("Sel, 4/4").format());