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,79 +1,79 @@
const cheerio = require('cheerio')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(customParseFormat)
module.exports = {
site: 'worldfishingnetwork.com',
days: 2,
url({ date }) {
return `https://www.worldfishingnetwork.com/schedule/77420?day=${date.format('ddd')}`
},
parser({ content, date }) {
const programs = []
const items = parseItems(content)
items.forEach(item => {
let $item = cheerio.load(item)
const prev = programs[programs.length - 1]
let start = parseStart($item, date)
if (prev) {
if (start.isBefore(prev.start)) {
start = start.add(1, 'd')
date = date.add(1, 'd')
}
prev.stop = start
}
const stop = start.add(30, 'm')
programs.push({
title: parseTitle($item),
sub_title: parseSubTitle($item),
description: parseDescription($item),
icon: parseIcon($item),
start,
stop
})
})
return programs
}
}
function parseTitle($item) {
return $item('.show-title > h3').text().trim()
}
function parseSubTitle($item) {
return $item('.show-title').clone().children().remove().end().text().trim()
}
function parseDescription($item) {
return $item('.show-title > p').text().trim()
}
function parseIcon($item) {
const url = $item('.show-img > img').attr('src')
return url ? `https:${url}` : null
}
function parseStart($item, date) {
const time = $item('.show-time > h2').clone().children().remove().end().text().trim()
const period = $item('.show-time > h2 > span > strong').text().trim()
return dayjs.tz(
`${date.format('YYYY-MM-DD')} ${time} ${period}`,
'YYYY-MM-DD HH:mm A',
'America/New_York'
)
}
function parseItems(content) {
const $ = cheerio.load(content)
return $('.show-item').toArray()
}
const cheerio = require('cheerio')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(customParseFormat)
module.exports = {
site: 'worldfishingnetwork.com',
days: 2,
url({ date }) {
return `https://www.worldfishingnetwork.com/schedule/77420?day=${date.format('ddd')}`
},
parser({ content, date }) {
const programs = []
const items = parseItems(content)
items.forEach(item => {
let $item = cheerio.load(item)
const prev = programs[programs.length - 1]
let start = parseStart($item, date)
if (prev) {
if (start.isBefore(prev.start)) {
start = start.add(1, 'd')
date = date.add(1, 'd')
}
prev.stop = start
}
const stop = start.add(30, 'm')
programs.push({
title: parseTitle($item),
sub_title: parseSubTitle($item),
description: parseDescription($item),
icon: parseIcon($item),
start,
stop
})
})
return programs
}
}
function parseTitle($item) {
return $item('.show-title > h3').text().trim()
}
function parseSubTitle($item) {
return $item('.show-title').clone().children().remove().end().text().trim()
}
function parseDescription($item) {
return $item('.show-title > p').text().trim()
}
function parseIcon($item) {
const url = $item('.show-img > img').attr('src')
return url ? `https:${url}` : null
}
function parseStart($item, date) {
const time = $item('.show-time > h2').clone().children().remove().end().text().trim()
const period = $item('.show-time > h2 > span > strong').text().trim()
return dayjs.tz(
`${date.format('YYYY-MM-DD')} ${time} ${period}`,
'YYYY-MM-DD HH:mm A',
'America/New_York'
)
}
function parseItems(content) {
const $ = cheerio.load(content)
return $('.show-item').toArray()
}

View File

@@ -1,55 +1,55 @@
// npm run grab -- --site=worldfishingnetwork.com
const { parser, url } = require('./worldfishingnetwork.com.config.js')
const fs = require('fs')
const path = require('path')
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('2023-01-24', 'YYYY-MM-DD').startOf('d')
it('can generate valid url', () => {
expect(url({ date })).toBe('https://www.worldfishingnetwork.com/schedule/77420?day=Tue')
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'), 'utf8')
let results = parser({ content, date })
results = results.map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results[0]).toMatchObject({
start: '2023-01-24T05:00:00.000Z',
stop: '2023-01-24T07:00:00.000Z',
title: 'Major League Fishing',
sub_title: 'Challenge Cup Sudden Death Round 2',
description:
'Nine anglers race to a target weight on Lake Wylie in the Lucas Oil Challenge Cup, presented by B&W Trailer Hitches, Rock Hill, South Carolina. Only four will move on to the Championship Round.',
icon: 'https://content.osgnetworks.tv/shows/major-league-fishing-thumbnail.jpg'
})
expect(results[41]).toMatchObject({
start: '2023-01-25T04:30:00.000Z',
stop: '2023-01-25T05:00:00.000Z',
title: 'Fishing 411',
sub_title: 'Flint Wilderness Walleye',
description:
'Mark Romanack and Bryan Darland fish walleye on Klotz Lake in the famed Flint Wilderness of Ontario',
icon: 'https://content.osgnetworks.tv/shows/fishin-411-thumbnail.jpg'
})
})
it('can handle empty guide', () => {
const results = parser({
date,
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'), 'utf8')
})
expect(results).toMatchObject([])
})
// npm run grab -- --site=worldfishingnetwork.com
const { parser, url } = require('./worldfishingnetwork.com.config.js')
const fs = require('fs')
const path = require('path')
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('2023-01-24', 'YYYY-MM-DD').startOf('d')
it('can generate valid url', () => {
expect(url({ date })).toBe('https://www.worldfishingnetwork.com/schedule/77420?day=Tue')
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'), 'utf8')
let results = parser({ content, date })
results = results.map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results[0]).toMatchObject({
start: '2023-01-24T05:00:00.000Z',
stop: '2023-01-24T07:00:00.000Z',
title: 'Major League Fishing',
sub_title: 'Challenge Cup Sudden Death Round 2',
description:
'Nine anglers race to a target weight on Lake Wylie in the Lucas Oil Challenge Cup, presented by B&W Trailer Hitches, Rock Hill, South Carolina. Only four will move on to the Championship Round.',
icon: 'https://content.osgnetworks.tv/shows/major-league-fishing-thumbnail.jpg'
})
expect(results[41]).toMatchObject({
start: '2023-01-25T04:30:00.000Z',
stop: '2023-01-25T05:00:00.000Z',
title: 'Fishing 411',
sub_title: 'Flint Wilderness Walleye',
description:
'Mark Romanack and Bryan Darland fish walleye on Klotz Lake in the famed Flint Wilderness of Ontario',
icon: 'https://content.osgnetworks.tv/shows/fishin-411-thumbnail.jpg'
})
})
it('can handle empty guide', () => {
const results = parser({
date,
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'), 'utf8')
})
expect(results).toMatchObject([])
})