diff --git a/cloud/scrapers/forumgroningen.ts b/cloud/scrapers/forumgroningen.ts index 581a8c6b..7d1e779e 100644 --- a/cloud/scrapers/forumgroningen.ts +++ b/cloud/scrapers/forumgroningen.ts @@ -4,7 +4,7 @@ import { DateTime } from 'luxon' import guessYear from './utils/guessYear' import { Screening } from '../types' import { logger as parentLogger } from '../powertools' -import { fullMonthToNumberDutch } from './utils/monthToNumber' +import { fullMonthToNumberEnglish } from './utils/monthToNumber' import splitTime from './utils/splitTime' const logger = parentLogger.createChild({ @@ -67,9 +67,9 @@ const extractFromMoviePage = async ({ .map(({ time }) => { const [dayOfWeek, dayString, monthString] = date.split(/\s+/) const day = Number(dayString) - const month = fullMonthToNumberDutch(monthString) + const month = fullMonthToNumberEnglish(monthString) const [startTime, endTime] = time.split(/ tot | till /) - const [hour, minute] = splitTime(startTime) + const { hour, minute } = DateTime.fromFormat(startTime, 'h:mm a') const year = guessYear({ day, @@ -104,10 +104,10 @@ const extractFromMainPage = async (): Promise => { const url = 'https://forum.nl/en/whats-on/international-movie-night' const movies = ( - await xray(url, '.content-row-medium.text-and-image', [ + await xray(url, '.calendar-list .ticket-row', [ { - title: 'h2 | cleanTitle | trim', - url: 'a@href', + title: '.content .main | cleanTitle | trim', + url: '@href', }, ]) ).filter(({ url }) => url !== undefined) // remove movies without url (e.g. in the past) @@ -125,10 +125,7 @@ const extractFromMainPage = async (): Promise => { if (require.main === module) { // extractFromMoviePage({ - // // url: 'https://forum.nl/nl/agenda/gaia', - // // url: 'https://forum.nl/nl/agenda/ringu', - // // url: 'https://forum.nl/nl/agenda/passages',p - // url: 'https://forum.nl/nl/agenda/pans-labyrinth', + // url: 'https://forum.nl/en/whats-on/the-zone-of-interest', // }) extractFromMainPage() diff --git a/cloud/scrapers/utils/monthToNumber.ts b/cloud/scrapers/utils/monthToNumber.ts index 3a9269d8..0c1ee243 100644 --- a/cloud/scrapers/utils/monthToNumber.ts +++ b/cloud/scrapers/utils/monthToNumber.ts @@ -1,5 +1,19 @@ -export const fullMonthToNumberDutch = (month: string) => { - const monthNumber = +const monthToNumber = (name: string, listOfMonths: string[], month: string) => { + const lowerCaseMonth = month.toLowerCase() + + const monthNumber = listOfMonths.indexOf(lowerCaseMonth) + 1 + if (monthNumber === 0) { + throw new Error( + `${name}: invalid month ${lowerCaseMonth}, might you need another function?`, + ) + } + + return monthNumber +} + +export function fullMonthToNumberDutch(month: string) { + return monthToNumber( + 'fullMonthToNumberDutch', [ 'januari', 'februari', @@ -13,19 +27,14 @@ export const fullMonthToNumberDutch = (month: string) => { 'oktober', 'november', 'december', - ].indexOf(month.toLowerCase()) + 1 - - if (monthNumber === 0) { - throw new Error( - `invalid month ${month}, might you need the English version of this function?`, - ) - } - - return monthNumber + ], + month, + ) } -export const shortMonthToNumberDutch = (month: string) => { - const monthNumber = +export function shortMonthToNumberDutch(month: string) { + return monthToNumber( + 'shortMonthToNumberDutch', [ 'jan', 'feb', @@ -39,19 +48,14 @@ export const shortMonthToNumberDutch = (month: string) => { 'okt', 'nov', 'dec', - ].indexOf(month.toLowerCase()) + 1 - - if (monthNumber === 0) { - throw new Error( - `invalid month ${month}, might you need the English version of this function?`, - ) - } - - return monthNumber + ], + month, + ) } -export const fullMonthToNumberEnglish = (month: string) => { - const monthNumber = +export function fullMonthToNumberEnglish(month: string) { + return monthToNumber( + 'fullMonthToNumberEnglish', [ 'january', 'february', @@ -65,19 +69,14 @@ export const fullMonthToNumberEnglish = (month: string) => { 'october', 'november', 'december', - ].indexOf(month.toLowerCase()) + 1 - - if (monthNumber === 0) { - throw new Error( - `invalid month ${month}, might you need the Dutch version of this function?`, - ) - } - - return monthNumber + ], + month, + ) } -export const shortMonthToNumberEnglish = (month: string) => { - const monthNumber = +export function shortMonthToNumberEnglish(month: string) { + return monthToNumber( + 'shortMonthToNumberEnglish', [ 'jan', 'feb', @@ -91,13 +90,7 @@ export const shortMonthToNumberEnglish = (month: string) => { 'oct', 'nov', 'dec', - ].indexOf(month.toLowerCase()) + 1 - - if (monthNumber === 0) { - throw new Error( - `invalid month ${month}, might you need the Dutch version of this function?`, - ) - } - - return monthNumber + ], + month, + ) }