From 4360499dd0e1e5fb58b8952b37d90c7e66da8de1 Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Sun, 2 Apr 2023 10:15:25 +0300 Subject: [PATCH 1/2] git ignoring dist --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b05ac72..399fb1c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ tmp config/client_google_auth.json ## output ## +dist From 831dfaaea0585491fb36b97e59556fe86f3d1c2d Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Sun, 2 Apr 2023 11:10:44 +0300 Subject: [PATCH 2/2] every day at 10am the script runs --- maccabi-haifa-fc.ics | 34 ++++++++++------------------------ package-lock.json | 17 +++++++++++++++++ package.json | 1 + src/index.ts | 24 +++++++++++++++++------- 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/maccabi-haifa-fc.ics b/maccabi-haifa-fc.ics index 716f1b8..9080565 100644 --- a/maccabi-haifa-fc.ics +++ b/maccabi-haifa-fc.ics @@ -5,23 +5,9 @@ PRODID:https://mhaifafc.com/ METHOD:PUBLISH X-PUBLISHED-TTL:PT1H BEGIN:VEVENT -UID:OOg8oTxogguu8rzrqhISi +UID:XM2mxB4gOmBM4OBkqWWW1 SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230330T060421Z -DTSTART:20230401T170000Z -DTEND:20230401T190000Z -DESCRIPTION:Maccabi Haifa vs. H Be'er Sheva -URL:https://mhaifafc.com/ -LOCATION:Sammy Ofer Stadium -STATUS:CONFIRMED -CATEGORIES: -ORGANIZER;CN=Maccabi Haifa F.C. -X-MICROSOFT-CDO-BUSYSTATUS:BUSY -END:VEVENT -BEGIN:VEVENT -UID:dF2NNZZYkoYqyT9lUvRUL -SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230330T060421Z +DTSTAMP:20230402T080845Z DTSTART:20230404T173000Z DTEND:20230404T193000Z DESCRIPTION:Maccabi Tel aviv vs. Maccabi Haifa @@ -33,9 +19,9 @@ ORGANIZER;CN=Maccabi Haifa F.C. X-MICROSOFT-CDO-BUSYSTATUS:BUSY END:VEVENT BEGIN:VEVENT -UID:w1jpYkmLHn22sPStvLVvX +UID:7P2E8_IBsTYsJlGkVZu7u SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230330T060421Z +DTSTAMP:20230402T080845Z DTSTART:20230408T170000Z DTEND:20230408T190000Z DESCRIPTION:Maccabi Haifa vs. Maccabi Netanya @@ -47,9 +33,9 @@ ORGANIZER;CN=Maccabi Haifa F.C. X-MICROSOFT-CDO-BUSYSTATUS:BUSY END:VEVENT BEGIN:VEVENT -UID:Ltl5msGiuujEh6aXPj7R6 +UID:cMHqpY5PoYZOG_IizeMXS SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230330T060421Z +DTSTAMP:20230402T080845Z DTSTART:20230415T153000Z DTEND:20230415T173000Z DESCRIPTION:Hapoel Jerusalem vs. Maccabi Haifa @@ -61,9 +47,9 @@ ORGANIZER;CN=Maccabi Haifa F.C. X-MICROSOFT-CDO-BUSYSTATUS:BUSY END:VEVENT BEGIN:VEVENT -UID:mhXQ-EHi3UTLDyP_f0X7C +UID:Z80kiSCKPEMLud1BUFxia SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230330T060421Z +DTSTAMP:20230402T080845Z DTSTART:20230423T173000Z DTEND:20230423T193000Z DESCRIPTION:F.C Ashdod vs. Maccabi Haifa @@ -75,9 +61,9 @@ ORGANIZER;CN=Maccabi Haifa F.C. X-MICROSOFT-CDO-BUSYSTATUS:BUSY END:VEVENT BEGIN:VEVENT -UID:rlUHEdqvIN_bym5lWst2Q +UID:mndtB--cUk1MicazqF1lv SUMMARY:Maccabi Haifa F.C. -DTSTAMP:20230330T060421Z +DTSTAMP:20230402T080845Z DTSTART:20230501T173000Z DTEND:20230501T193000Z DESCRIPTION:H Be'er Sheva vs. Maccabi Haifa diff --git a/package-lock.json b/package-lock.json index baa5ac2..2207469 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,6 +6,7 @@ "": { "dependencies": { "axios": "^1.3.4", + "cron": "^2.3.0", "dotenv": "^16.0.3", "googleapis": "^113.0.0", "ics": "^3.1.0", @@ -132,6 +133,14 @@ "node": ">= 0.8" } }, + "node_modules/cron": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/cron/-/cron-2.3.0.tgz", + "integrity": "sha512-ZN5HP8zDY41sJolMsbc+GksRATcbvkPKF5wR/qc8FrV4NBVi9ORQa1HmYa5GydaysUB80X9XpRlRkooa5uEtTA==", + "dependencies": { + "luxon": "^3.2.1" + } + }, "node_modules/css-select": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", @@ -530,6 +539,14 @@ "node": ">=10" } }, + "node_modules/luxon": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.3.0.tgz", + "integrity": "sha512-An0UCfG/rSiqtAIiBPO0Y9/zAnHUZxAMiCpTd5h2smgsj7GGmcenvrvww2cqNA8/4A5ZrD1gJpHN2mIHZQF+Mg==", + "engines": { + "node": ">=12" + } + }, "node_modules/mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", diff --git a/package.json b/package.json index 59771ee..a1d5be1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "dependencies": { "axios": "^1.3.4", + "cron": "^2.3.0", "dotenv": "^16.0.3", "googleapis": "^113.0.0", "ics": "^3.1.0", diff --git a/src/index.ts b/src/index.ts index 6651904..bca031d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,8 @@ import GameSource from './GameSource'; import fs from 'fs'; import Ics from './Ics'; +const CronJob = require('cron').CronJob; + class App { googleCalendar: GoogleCalendar; @@ -31,11 +33,19 @@ class App { const app = new App(); -const start = async () => { - const outputFileLocation = 'maccabi-haifa-fc.ics'; - const games = await app.gameSource.getGamesFromHaifa(); - const icsEvents = app.ics.generateIcsOutputFromGames(games); - fs.writeFileSync(outputFileLocation, icsEvents); -} -start(); \ No newline at end of file +const job = new CronJob( + "0 10 * * *", + async () => { + console.log("START") + const outputFileLocation = 'maccabi-haifa-fc.ics'; + const games = await app.gameSource.getGamesFromHaifa(); + const icsEvents = app.ics.generateIcsOutputFromGames(games); + fs.writeFileSync(outputFileLocation, icsEvents); + }, + null, + true, + 'Asia/Jerusalem' +); + +