diff --git a/package.json b/package.json index f7d8b1e..876cd9c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "cron": "^2.3.0", "dotenv": "^16.0.3", "express": "^4.18.2", - "googleapis": "^113.0.0", "ical": "^0.8.0", "ics": "^3.1.0", "moment": "^2.29.4", diff --git a/src/GoogleCalendar.ts b/src/GoogleCalendar.ts index a93eea5..ffba0cb 100644 --- a/src/GoogleCalendar.ts +++ b/src/GoogleCalendar.ts @@ -1,65 +1,65 @@ -import { JWT } from 'google-auth-library'; -import { google } from 'googleapis'; -import { GoogleCalendarEvent } from './types/index'; +// import { JWT } from 'google-auth-library'; +// import { google } from 'googleapis'; +// import { GoogleCalendarEvent } from './types/index'; -require('dotenv').config(); -const env = process.env; +// require('dotenv').config(); +// const env = process.env; -export default class GoogleCalendar { - clientSecret: string = env.GOOGLE_CLIENT_SECRET; - clientId: string = env.GOOGLE_CLIENT_ID; - calenderId: string = env.GOOGLE_CALENDAR_ID; - calendar: any; - clientEmail: string = env.GOOGLE_CLIENT_EMAIL; - googlePrivateKey: string = env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, '\n'); - token: any; - JWT_client: JWT; +// export default class GoogleCalendar { +// clientSecret: string = env.GOOGLE_CLIENT_SECRET; +// clientId: string = env.GOOGLE_CLIENT_ID; +// calenderId: string = env.GOOGLE_CALENDAR_ID; +// calendar: any; +// clientEmail: string = env.GOOGLE_CLIENT_EMAIL; +// googlePrivateKey: string = env.GOOGLE_PRIVATE_KEY.replace(/\\n/g, '\n'); +// token: any; +// JWT_client: JWT; - async init() { - console.log("INIT GOOGLE CALENDAR") - const jwtClient = await this.authorize(); - this.calendar = google.calendar({ version: 'v3', auth: jwtClient }); - console.log("DONE INIT GOOGLE CALENDAR") - } +// async init() { +// console.log("INIT GOOGLE CALENDAR") +// const jwtClient = await this.authorize(); +// this.calendar = google.calendar({ version: 'v3', auth: jwtClient }); +// console.log("DONE INIT GOOGLE CALENDAR") +// } - async authorize() { - console.log("AUTHORIZE GOOGLE CALENDAR") - this.JWT_client = new JWT({ - email: this.clientEmail, - key: this.googlePrivateKey, - scopes: [ - 'https://www.googleapis.com/auth/calendar', - ] - }); - const { access_token } = await this.JWT_client.authorize(); - this.token = access_token; - if (!this.token) { - throw new Error('Failed to connect to google calendar'); - } - console.log("GOOGLE CALENDAR AUTHORIZED SUCCESSFULLY") - return this.JWT_client; - } +// async authorize() { +// console.log("AUTHORIZE GOOGLE CALENDAR") +// this.JWT_client = new JWT({ +// email: this.clientEmail, +// key: this.googlePrivateKey, +// scopes: [ +// 'https://www.googleapis.com/auth/calendar', +// ] +// }); +// const { access_token } = await this.JWT_client.authorize(); +// this.token = access_token; +// if (!this.token) { +// throw new Error('Failed to connect to google calendar'); +// } +// console.log("GOOGLE CALENDAR AUTHORIZED SUCCESSFULLY") +// return this.JWT_client; +// } - 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); - return; - } - console.log(event.description + ' created'); - }); +// 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); +// return; +// } +// console.log(event.description + ' created'); +// }); - }) - }, 3000) +// }) +// }, 3000) - } -} +// } +// } diff --git a/src/index.ts b/src/index.ts index 7ca829e..2bd6ce9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import GoogleCalendar from './GoogleCalendar'; +// import GoogleCalendar from './GoogleCalendar'; import GameSource from './GameSource'; import fs from 'fs'; import Ics from './Ics'; @@ -8,28 +8,28 @@ import env from 'dotenv'; env.config(); class App { - googleCalendar: GoogleCalendar; + // googleCalendar: GoogleCalendar; gameSource: GameSource; ics: Ics; googleToken: string; constructor() { - this.googleCalendar = new GoogleCalendar(); + // this.googleCalendar = new GoogleCalendar(); this.gameSource = new GameSource(); this.ics = new Ics(); } - async init() { - console.log("INIT APP") - await this.googleCalendar.init(); - } + // 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 getNewGamesAndUpdateCalendar() { + // console.log("GET NEW GAMES AND UPDATE CALENDAR") + // const games = await this.gameSource.getGamesFromHaifa(); + // this.googleCalendar.updateNewEvent(games); + // } async startCronJob() { console.log("START CRON JOB")