timeout each googleApi request
This commit is contained in:
parent
2daf19e30a
commit
e7efa713eb
3 changed files with 28 additions and 21 deletions
|
@ -30,12 +30,16 @@ export default class GameSource {
|
|||
for (let gameBox of gameBoxs) {
|
||||
|
||||
const teamsPlaying = gameBox.querySelectorAll(".team-name").map((team: any) => team.text);
|
||||
console.log("TEAMS PLAYING", teamsPlaying)
|
||||
const regex = /[\r\n\s]+/g;
|
||||
const gameHeader = gameBox.querySelector(".game-header").text.replace(regex, " ").trim();
|
||||
console.log("GAME HEADER", gameHeader)
|
||||
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 gameTime = headerSplit[3].trim();
|
||||
|
||||
|
|
|
@ -41,16 +41,18 @@ export default class GoogleCalendar {
|
|||
return this.JWT_client;
|
||||
}
|
||||
|
||||
updateNewEvent(upcomingEvents: GoogleCalendarEvent[]) {
|
||||
async updateNewEvent(upcomingEvents: GoogleCalendarEvent[]) {
|
||||
|
||||
|
||||
|
||||
setTimeout(async () => {
|
||||
upcomingEvents.forEach((event: GoogleCalendarEvent) => {
|
||||
console.log("UPDATE NEW EVENT", upcomingEvents)
|
||||
|
||||
const options = {
|
||||
auth: this.JWT_client,
|
||||
calendarId: this.calenderId,
|
||||
resource: event,
|
||||
}
|
||||
|
||||
this.calendar.events.insert(options, function (err: any, event: any) {
|
||||
if (err) {
|
||||
console.log('There was an error contacting the Calendar service: ' + err);
|
||||
|
@ -60,6 +62,7 @@ export default class GoogleCalendar {
|
|||
});
|
||||
|
||||
})
|
||||
}, 3000)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ class App {
|
|||
|
||||
|
||||
const games = await this.gameSource.getGamesFromHaifa();
|
||||
// console.log(games)
|
||||
this.googleCalendar.updateNewEvent(games);
|
||||
}
|
||||
}
|
||||
|
@ -43,4 +44,3 @@ const start = async () => {
|
|||
await app.getNewGamesAndUpdateCalendar();
|
||||
}
|
||||
start();
|
||||
// console.log(moment("Sel, 4/4").format());
|
||||
|
|
Loading…
Reference in a new issue