Skip to content

Commit

Permalink
fix forumgroningen (website changed from NL to EN)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckuijjer committed Mar 22, 2024
1 parent ba2e7a1 commit 4ca404d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 54 deletions.
17 changes: 7 additions & 10 deletions cloud/scrapers/forumgroningen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -104,10 +104,10 @@ const extractFromMainPage = async (): Promise<Screening[]> => {
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)
Expand All @@ -125,10 +125,7 @@ const extractFromMainPage = async (): Promise<Screening[]> => {

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()
Expand Down
81 changes: 37 additions & 44 deletions cloud/scrapers/utils/monthToNumber.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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,
)
}

0 comments on commit 4ca404d

Please sign in to comment.