removed google api + changing game info

This commit is contained in:
Kfir Dayan 2023-04-16 14:53:39 +03:00
parent d512ca8197
commit 0fea123354
2 changed files with 12 additions and 25 deletions

View file

@ -12,31 +12,33 @@ export default class Ics {
output.push(this.generateIcsOutputFromGame(game)); output.push(this.generateIcsOutputFromGame(game));
}); });
console.log(output)
const { error, value } = ics.createEvents(output); const { error, value } = ics.createEvents(output);
if (error) { if (error) {
console.log(error); console.log(error);
return ''; return '';
} }
console.log(value);
return value; return value;
} }
generateIcsOutputFromGame = (game: GoogleCalendarEvent) => { generateIcsOutputFromGame = (game: GoogleCalendarEvent) => {
const { summary, location, description, start, end } = game; const { summary, location, description, start, end } = game;
const icsEvent: ics.EventAttributes = { const icsEvent: ics.EventAttributes = {
title: summary, title: description,
description, description,
location, location,
start: [start.dateTime[0], start.dateTime[1], start.dateTime[2], start.dateTime[3], start.dateTime[4]], start: [start.dateTime[0], start.dateTime[1], start.dateTime[2], start.dateTime[3], start.dateTime[4]],
end: [end.dateTime[0], end.dateTime[1], end.dateTime[2], end.dateTime[3], end.dateTime[4]], end: [end.dateTime[0], end.dateTime[1], end.dateTime[2], end.dateTime[3], end.dateTime[4]],
url: 'https://mhaifafc.com/',
status: 'CONFIRMED', status: 'CONFIRMED',
busyStatus: 'BUSY', busyStatus: 'BUSY',
productId: 'https://mhaifafc.com/', productId: '-//kfir.dayanhub.com',
recurrenceRule: '', recurrenceRule: '',
attendees: [], attendees: [],
alarms: [], alarms: [],
categories: [], categories: [],
organizer: { name: 'Maccabi Haifa F.C.', email: '' } organizer: { name: 'Maccabi Haifa F.C.', email: '' },
}; };
return icsEvent; return icsEvent;
} }

View file

@ -1,4 +1,3 @@
// import GoogleCalendar from './GoogleCalendar';
import GameSource from './GameSource'; import GameSource from './GameSource';
import fs from 'fs'; import fs from 'fs';
import Ics from './Ics'; import Ics from './Ics';
@ -8,29 +7,15 @@ import env from 'dotenv';
env.config(); env.config();
class App { class App {
// googleCalendar: GoogleCalendar;
gameSource: GameSource; gameSource: GameSource;
ics: Ics; ics: Ics;
googleToken: string; googleToken: string;
constructor() { constructor() {
// this.googleCalendar = new GoogleCalendar();
this.gameSource = new GameSource(); this.gameSource = new GameSource();
this.ics = new Ics(); this.ics = new Ics();
} }
// async init() {
// console.log("INIT APP")
// await this.googleCalendar.init();
// }
// async getNewGamesAndUpdateCalendar() {
// console.log("GET NEW GAMES AND UPDATE CALENDAR")
// const games = await this.gameSource.getGamesFromHaifa();
// this.googleCalendar.updateNewEvent(games);
// }
async startCronJob() { async startCronJob() {
console.log("START CRON JOB") console.log("START CRON JOB")
const CronJob = require('cron').CronJob; const CronJob = require('cron').CronJob;
@ -42,16 +27,16 @@ class App {
console.log("Getting games from Haifa") console.log("Getting games from Haifa")
const games = await app.gameSource.getGamesFromHaifa(); const games = await app.gameSource.getGamesFromHaifa();
console.log("Generating ICS file") console.log("Generating ICS file")
const icsEvents = app.ics.generateIcsOutputFromGames(games); const icsEvents = app.ics.generateIcsOutputFromGames([games[0]]);
console.log("Writing ICS file to " + outputFileLocation) console.log("Writing ICS file to " + outputFileLocation)
fs.writeFileSync(outputFileLocation, icsEvents); fs.writeFileSync(outputFileLocation, icsEvents);
console.log("Done Ics file") console.log("Done Ics file")
console.log("converting ics file to ical file") // console.log("converting ics file to ical file")
const outputIcalFileLocation = 'public/maccabi-haifa-fc.ical'; // const outputIcalFileLocation = 'public/maccabi-haifa-fc.ical';
const icalEvents = app.ics.convertIcsToIcal(icsEvents); // const icalEvents = app.ics.convertIcsToIcal(icsEvents);
console.log("Writing Ical file to " + outputIcalFileLocation) // console.log("Writing Ical file to " + outputIcalFileLocation)
fs.writeFileSync(outputIcalFileLocation, icalEvents); // fs.writeFileSync(outputIcalFileLocation, icalEvents);
}, },
null, null,