From dd5e3aa18aa9312ceee64839a9c67c1a96527aa4 Mon Sep 17 00:00:00 2001 From: Toha Date: Sat, 23 Nov 2024 22:48:33 +0700 Subject: [PATCH] Update moji.id guide. Change site language to id and fix test. Signed-off-by: Toha --- sites/moji.id/moji.id.channels.xml | 2 +- sites/moji.id/moji.id.config.js | 83 +++++++++++------------------- sites/moji.id/moji.id.test.js | 15 +++--- 3 files changed, 39 insertions(+), 61 deletions(-) diff --git a/sites/moji.id/moji.id.channels.xml b/sites/moji.id/moji.id.channels.xml index bd1c7d55..530f52af 100644 --- a/sites/moji.id/moji.id.channels.xml +++ b/sites/moji.id/moji.id.channels.xml @@ -1,4 +1,4 @@ - Moji + Moji \ No newline at end of file diff --git a/sites/moji.id/moji.id.config.js b/sites/moji.id/moji.id.config.js index 2a942104..80c1baf7 100644 --- a/sites/moji.id/moji.id.config.js +++ b/sites/moji.id/moji.id.config.js @@ -9,33 +9,15 @@ dayjs.extend(timezone) dayjs.extend(customParseFormat) const currentYear = new Date().getFullYear() +const tz = 'Asia/Jakarta' module.exports = { site: 'moji.id', - days: 4, - output: 'moji.id.guide.xml', - channels: 'moji.id.channels.xml', - lang: 'en', - delay: 5000, - - url: function () { - return 'https://moji.id/schedule' - }, - - request: { - method: 'GET', - timeout: 5000, - cache: { ttl: 60 * 60 * 1000 }, - headers: { - 'User-Agent': - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36' - } - }, - + days: 2, + url: 'https://moji.id/schedule', logo: function (context) { return context.channel.logo }, - parser: function (context) { const programs = [] const items = parseItems(context) @@ -60,15 +42,16 @@ function parseItems(context) { const monthDate = dayjs(context.date).format('MMM DD') const items = [] - schDayMonths.forEach(function (schDayMonth, i) { + schDayMonths.forEach((schDayMonth, i) => { if (monthDate == $(schDayMonth).text()) { - let schDayPrograms = $(schPrograms[i]).find('.accordion').toArray() - schDayPrograms.forEach(function (program, i) { - let itemDay = { - progStart: parseStart(schDayMonth, program), - progStop: parseStop(schDayMonth, program, schDayPrograms[i + 1]), - progTitle: parseTitle(program), - progDesc: parseDescription(program) + const schDayPrograms = $(schPrograms[i]).find('.accordion').toArray() + schDayPrograms.forEach((program, i) => { + const itemDay = { + progStart: parseStart($(schDayMonth), $(program)), + progStop: parseStop($(schDayMonth), schDayPrograms[i + 1] ? + $(schDayPrograms[i + 1]) : null), + progTitle: parseTitle($(program)), + progDesc: parseDescription($(program)) } items.push(itemDay) }) @@ -79,44 +62,38 @@ function parseItems(context) { } function parseTitle(item) { - return cheerio.load(item)('.name-prog').text() + return item.find('.name-prog').text() } function parseDescription(item) { - return cheerio.load(item)('.content-acc span').text() + return item.find('.content-acc span').text() } function parseStart(schDayMonth, item) { - let monthDate = cheerio.load(schDayMonth).text().split(' ') - let startTime = cheerio.load(item)('.pkl').text() - let progStart = dayjs.tz( - currentYear + ' ' + monthDate[0] + ' ' + monthDate[1] + ' ' + startTime, - 'YYYY MMM DD HH:mm', - 'Asia/Jakarta' + const monthDate = schDayMonth.text().split(' ') + const startTime = item.find('.pkl').text() + + return dayjs.tz( + `${currentYear}-${monthDate[0]}-${monthDate[1]} ${startTime}`, + 'YYYY-MMM-DD HH:mm', + tz ) - return progStart } -function parseStop(schDayMonth, itemCurrent, itemNext) { - let monthDate = cheerio.load(schDayMonth).text().split(' ') - +function parseStop(schDayMonth, itemNext) { + const monthDate = schDayMonth.text().split(' ') if (itemNext) { - let stopTime = cheerio.load(itemNext)('.pkl').text() + const stopTime = itemNext.find('.pkl').text() return dayjs.tz( - currentYear + ' ' + monthDate[0] + ' ' + monthDate[1] + ' ' + stopTime, - 'YYYY MMM DD HH:mm', - 'Asia/Jakarta' + `${currentYear}-${monthDate[0]}-${monthDate[1]} ${stopTime}`, + 'YYYY-MMM-DD HH:mm', + tz ) } else { return dayjs.tz( - currentYear + - ' ' + - monthDate[0] + - ' ' + - (parseInt(monthDate[1]) + 1).toString().padStart(2, '0') + - ' 00:00', - 'YYYY MMM DD HH:mm', - 'Asia/Jakarta' + `${currentYear}-${monthDate[0]}-${(parseInt(monthDate[1]) + 1).toString().padStart(2, '0')} 00:00`, + 'YYYY-MMM-DD HH:mm', + tz ) } } diff --git a/sites/moji.id/moji.id.test.js b/sites/moji.id/moji.id.test.js index 406083ba..ca2ddc55 100644 --- a/sites/moji.id/moji.id.test.js +++ b/sites/moji.id/moji.id.test.js @@ -14,22 +14,23 @@ const channel = { const content = '

schedule

FriAug 18
SatAug 19
SunAug 20
Jam TayangProgram
00:00TRUST
Informasi seputar menjaga vitalitas pria
00:302023 AVC CHALLENGE CUP FOR WOMEN (RECORDED)
India Vs. Vietnam
02:30ONE CHAMPIONSHIP 2021
Siaran laga-laga pertandingan tinju gaya bebas internasional. Meyuguhkan pertarungan sengit dari para petarung profeisional kelas dunia.
03:30VOLLEYBALL NATION\'S LEAGUE 2023 (RECORDED)
TURKI vs BRAZIL
05:00MOJI SPORT
MOJI SPORT
06:15LIPUTAN 6 PAGI MOJI
Kompilasi ragam berita hard news dan soft news baik dari dalam negeri maupun internasional juga info prediksi cuaca di wilayah Indonesia
07:00UNGKAP
Liputan investigasi seputar berbagai topik dan peristiwa hangat serta kontroversial yang terjadi di Indonesia
08:00PIALA KAPOLRI 2023 PUTRI (LIVE)
PIALA KAPOLRI 2023 PUTRI (LIVE)
10:30SERIES PAGI
GANTENG GANTENG SERIGALA
12:30DIAM-DIAM SUKA
DIAM-DIAM SUKA
13:30PIALA KAPOLRI 2023 PUTRA (LIVE)
PIALA KAPOLRI 2023 PUTRA (LIVE)
16:00PIALA KAPOLRI 2023 PUTRI (LIVE)
PIALA KAPOLRI 2023 PUTRI (LIVE)
18:00PIALA KAPOLRI 2023 PUTRA (LIVE)
PIALA KAPOLRI 2023 PUTRA (LIVE)
20:00MOJI DRAMA (CHHOTI SARDARNI)
CHHOTI SARDARNI
21:30SINEMA MALAM (BIDADARI CANTIK DI RUMAH KOST)
(BIDADARI CANTIK DI RUMAH KOST
23:00TRUST
Informasi seputar menjaga vitalitas pria
23:30TRUST
Informasi seputar menjaga vitalitas pria
' -it('can generate valid url', () => { - expect(url({ channel, date })).toBe('https://moji.id/schedule') -}) - it('can handle empty guide', () => { const results = parser({ content: '' }) expect(results).toMatchObject([]) }) it('can parse response', () => { - const results = parser({ content: content, date: date }) + const results = parser({ content, date }) + .map(p => { + p.start = p.start.year(2023).toJSON() + p.stop = p.stop.year(2023).toJSON() + return p + }) expect(results[0]).toMatchObject({ title: 'TRUST', - start: dayjs.tz('2023 Aug 18 00:00', 'YYYY MMM DD HH:mm', 'Asia/Jakarta'), - stop: dayjs.tz('2023 Aug 18 00:30', 'YYYY MMM DD HH:mm', 'Asia/Jakarta'), + start: '2023-08-17T17:00:00.000Z', + stop: '2023-08-17T17:30:00.000Z', description: 'Informasi seputar menjaga vitalitas pria' }) })