Fixes linter errors

This commit is contained in:
freearhey
2023-10-15 14:08:23 +03:00
parent 57e508fc3b
commit 63c86a2b30
393 changed files with 28447 additions and 28443 deletions

View File

@@ -1,41 +1,41 @@
const dayjs = require('dayjs')
const isBetween = require('dayjs/plugin/isBetween')
dayjs.extend(isBetween)
module.exports = {
site: 'pbsguam.org',
days: 2, // the program is only available Thursday through Sunday
url: 'https://pbsguam.org/calendar/',
parser: function ({ content, date }) {
let programs = []
const items = parseItems(content, date)
items.forEach(item => {
programs.push({
title: item.title,
start: dayjs(item.start),
stop: dayjs(item.end)
})
})
return programs
}
}
function parseItems(content, date) {
const [, json] = content.match(/EventsSchedule_1 = (.*);/i) || [null, '']
let data
try {
data = JSON.parse(json)
} catch (error) {
return []
}
if (!data || !Array.isArray(data.feed)) return []
return data.feed.filter(
i =>
dayjs(i.start).isBetween(date, date.add(1, 'd')) ||
dayjs(i.end).isBetween(date, date.add(1, 'd'))
)
}
const dayjs = require('dayjs')
const isBetween = require('dayjs/plugin/isBetween')
dayjs.extend(isBetween)
module.exports = {
site: 'pbsguam.org',
days: 2, // the program is only available Thursday through Sunday
url: 'https://pbsguam.org/calendar/',
parser: function ({ content, date }) {
let programs = []
const items = parseItems(content, date)
items.forEach(item => {
programs.push({
title: item.title,
start: dayjs(item.start),
stop: dayjs(item.end)
})
})
return programs
}
}
function parseItems(content, date) {
const [, json] = content.match(/EventsSchedule_1 = (.*);/i) || [null, '']
let data
try {
data = JSON.parse(json)
} catch (error) {
return []
}
if (!data || !Array.isArray(data.feed)) return []
return data.feed.filter(
i =>
dayjs(i.start).isBetween(date, date.add(1, 'd')) ||
dayjs(i.end).isBetween(date, date.add(1, 'd'))
)
}

View File

@@ -1,48 +1,48 @@
// npm run grab -- --site=pbsguam.org
const { parser, url } = require('./pbsguam.org.config.js')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
dayjs.extend(utc)
const date = dayjs.utc('2021-11-25', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '#',
xmltv_id: 'KGTF.us'
}
it('can generate valid url', () => {
expect(url).toBe('https://pbsguam.org/calendar/')
})
it('can parse response', () => {
const content = `<!DOCTYPE html><html lang="en-US"> <head></head> <body> <script type='text/javascript' id='wcs-main-js-extra'>
/* <![CDATA[ */
var EventsSchedule_1 = {"feed":[{"title":"Xavier Riddle and the Secret Museum","id":5097,"thumbnail":false,"thumbnail_size":false,"multiday":false,"ending":"","duration":"30'","terms":[],"period":30,"excerpt":"","hash":"5d7710f569fec3fb1839bd7e5ad87038","visible":true,"timestamp":1637829000,"last":false,"start":"2021-11-25T08:30:00+00:00","end":"2021-11-25T09:00:00+00:00","future":true,"finished":false,"permalink":"https://pbsguam.org/class/xavier-riddle-and-the-secret-museum/?wcs_timestamp=1637829000","buttons":[],"meta":[]},{"title":"Austin City Limits","id":3916,"thumbnail":false,"thumbnail_size":false,"multiday":false,"ending":"","duration":"1h","terms":[],"period":60,"excerpt":"","hash":"1255a0a23db3b726b38a5384147ec677","visible":true,"timestamp":1638140400,"last":false,"start":"2021-11-28T23:00:00+00:00","end":"2021-11-29T00:00:00+00:00","future":true,"finished":false,"permalink":"https://pbsguam.org/class/austin-city-limits/?wcs_timestamp=1638140400","buttons":[],"meta":[]}]};
/* ]]> */
</script> </body></html>`
const result = parser({ date, content }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(result).toMatchObject([
{
start: '2021-11-25T08:30:00.000Z',
stop: '2021-11-25T09:00:00.000Z',
title: 'Xavier Riddle and the Secret Museum'
}
])
})
it('can handle empty guide', () => {
const result = parser({
date,
channel,
content: '<html> <head></head> <body></body></html>'
})
expect(result).toMatchObject([])
})
// npm run grab -- --site=pbsguam.org
const { parser, url } = require('./pbsguam.org.config.js')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
dayjs.extend(utc)
const date = dayjs.utc('2021-11-25', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '#',
xmltv_id: 'KGTF.us'
}
it('can generate valid url', () => {
expect(url).toBe('https://pbsguam.org/calendar/')
})
it('can parse response', () => {
const content = `<!DOCTYPE html><html lang="en-US"> <head></head> <body> <script type='text/javascript' id='wcs-main-js-extra'>
/* <![CDATA[ */
var EventsSchedule_1 = {"feed":[{"title":"Xavier Riddle and the Secret Museum","id":5097,"thumbnail":false,"thumbnail_size":false,"multiday":false,"ending":"","duration":"30'","terms":[],"period":30,"excerpt":"","hash":"5d7710f569fec3fb1839bd7e5ad87038","visible":true,"timestamp":1637829000,"last":false,"start":"2021-11-25T08:30:00+00:00","end":"2021-11-25T09:00:00+00:00","future":true,"finished":false,"permalink":"https://pbsguam.org/class/xavier-riddle-and-the-secret-museum/?wcs_timestamp=1637829000","buttons":[],"meta":[]},{"title":"Austin City Limits","id":3916,"thumbnail":false,"thumbnail_size":false,"multiday":false,"ending":"","duration":"1h","terms":[],"period":60,"excerpt":"","hash":"1255a0a23db3b726b38a5384147ec677","visible":true,"timestamp":1638140400,"last":false,"start":"2021-11-28T23:00:00+00:00","end":"2021-11-29T00:00:00+00:00","future":true,"finished":false,"permalink":"https://pbsguam.org/class/austin-city-limits/?wcs_timestamp=1638140400","buttons":[],"meta":[]}]};
/* ]]> */
</script> </body></html>`
const result = parser({ date, content }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(result).toMatchObject([
{
start: '2021-11-25T08:30:00.000Z',
stop: '2021-11-25T09:00:00.000Z',
title: 'Xavier Riddle and the Secret Museum'
}
])
})
it('can handle empty guide', () => {
const result = parser({
date,
channel,
content: '<html> <head></head> <body></body></html>'
})
expect(result).toMatchObject([])
})