diff --git a/sites/antennapacific.gr/__data__/content.html b/sites/antennapacific.gr/__data__/content.html new file mode 100644 index 00000000..23f649f2 --- /dev/null +++ b/sites/antennapacific.gr/__data__/content.html @@ -0,0 +1,1078 @@ + + + + + + + + + + + + + + Πρόγραμμα + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + +
+
+
+ +
+
+ +
+
+
+
+
    +
    + +
    +
    + +
    + + + + +
    +
    +
    +
    + +
    Άρχισε να πληκτρολογείς οτιδήποτε
    +
    +
    +
    +
    +
    +
    + +
    + +
    +

    Δες επίσης

    +
    +
    +
    +
    +
    +
    +
    +

    Πρόγραμμα

    + +
    + + + +
    + + + + + + + + + + + + + + + diff --git a/sites/antennapacific.gr/__data__/no_content.html b/sites/antennapacific.gr/__data__/no_content.html new file mode 100644 index 00000000..548eaca4 --- /dev/null +++ b/sites/antennapacific.gr/__data__/no_content.html @@ -0,0 +1,916 @@ + + + + + + + + + + + + + + Πρόγραμμα + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    + + +
    +
    +
    + +
    +
    + +
    +
    +
    +
    +
      +
      + +
      +
      + +
      + + + + +
      +
      +
      +
      + +
      Άρχισε να πληκτρολογείς οτιδήποτε
      +
      +
      +
      +
      +
      +
      + +
      + +
      +

      Δες επίσης

      +
      +
      +
      +
      +
      +
      +
      +

      Πρόγραμμα

      + +
      + + + +
      + + + + + + + + + + + + + + + diff --git a/sites/antennapacific.gr/antennapacific.gr.channels.xml b/sites/antennapacific.gr/antennapacific.gr.channels.xml new file mode 100644 index 00000000..25608020 --- /dev/null +++ b/sites/antennapacific.gr/antennapacific.gr.channels.xml @@ -0,0 +1,4 @@ + + + ANT1 PACIFIC + diff --git a/sites/antennapacific.gr/antennapacific.gr.config.js b/sites/antennapacific.gr/antennapacific.gr.config.js new file mode 100644 index 00000000..a0b06e29 --- /dev/null +++ b/sites/antennapacific.gr/antennapacific.gr.config.js @@ -0,0 +1,59 @@ +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: 'antennapacific.gr', + days: 2, + url({ date }) { + return `https://www.antennapacific.gr/el/tvguide.html?date=${date.format('YYYY-MM-DD')}` + }, + parser({ content, date }) { + const programs = [] + const items = parseItems(content, date) + items.forEach(item => { + const $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), + start, + stop + }) + }) + + return programs + } +} + +function parseTitle($item) { + return $item('.title').text().trim() +} + +function parseStart($item, date) { + const time = $item('dt.col-time').clone().children().remove().end().text().trim() + + return time + ? dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', 'Europe/Athens') + : null +} + +function parseItems(content) { + const $ = cheerio.load(content) + + return $('dl.show').toArray() +} diff --git a/sites/antennapacific.gr/antennapacific.gr.test.js b/sites/antennapacific.gr/antennapacific.gr.test.js new file mode 100644 index 00000000..2047519a --- /dev/null +++ b/sites/antennapacific.gr/antennapacific.gr.test.js @@ -0,0 +1,46 @@ +const { parser, url } = require('./antennapacific.gr.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('2025-01-21', 'YYYY-MM-DD').startOf('d') + +it('can generate valid url', () => { + expect(url({ date })).toBe('https://www.antennapacific.gr/el/tvguide.html?date=2025-01-21') +}) + +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.length).toBe(17) + + expect(results[0]).toMatchObject({ + start: '2025-01-21T05:00:00.000Z', + stop: '2025-01-21T06:00:00.000Z', + title: 'ANT1 NEWS - ΚΕΝΤΡΙΚΟ ΔΕΛΤΙΟ' + }) + + expect(results[16]).toMatchObject({ + start: '2025-01-22T02:45:00.000Z', + stop: '2025-01-22T03:15:00.000Z', + title: 'ΚΑΛΗΜΕΡΑ ΕΛΛΑΔΑ' + }) +}) + +it('can handle empty guide', () => { + const results = parser({ + date, + content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'), 'utf8') + }) + expect(results).toMatchObject([]) +}) diff --git a/sites/antennapacific.gr/readme.md b/sites/antennapacific.gr/readme.md new file mode 100644 index 00000000..86238ca7 --- /dev/null +++ b/sites/antennapacific.gr/readme.md @@ -0,0 +1,15 @@ +# antennapacific.gr + +https://www.antennapacific.gr/el/tvguide.html + +### Download the guide + +```sh +npm run grab --- --site=antennapacific.gr +``` + +### Test + +```sh +npm test --- antennapacific.gr +```