From 247d3ff877593af48dd13aff0ef958059024cf1d Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 5 Mar 2022 22:48:32 +0300 Subject: [PATCH 1/4] Create kan.org.il.config.js --- sites/kan.org.il/kan.org.il.config.js | 51 +++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 sites/kan.org.il/kan.org.il.config.js diff --git a/sites/kan.org.il/kan.org.il.config.js b/sites/kan.org.il/kan.org.il.config.js new file mode 100644 index 00000000..b4733a1c --- /dev/null +++ b/sites/kan.org.il/kan.org.il.config.js @@ -0,0 +1,51 @@ +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: 'kan.org.il', + url: function ({ channel, date }) { + return `https://www.kan.org.il/tv-guide/tv_guidePrograms.ashx?stationID=${ + channel.site_id + }&day=${date.format('DD/MM/YYYY')}` + }, + parser: function ({ content }) { + let programs = [] + const items = parseItems(content) + items.forEach(item => { + programs.push({ + title: item.title, + description: item.live_desc, + icon: item.picture_code, + start: parseStart(item), + stop: parseStop(item) + }) + }) + + return programs + } +} + +function parseStart(item) { + if (!item.start_time) return null + + return dayjs.tz(item.start_time, 'YYYY-MM-DDTHH:mm:ss', 'Asia/Jerusalem') +} + +function parseStop(item) { + if (!item.end_time) return null + + return dayjs.tz(item.end_time, 'YYYY-MM-DDTHH:mm:ss', 'Asia/Jerusalem') +} + +function parseItems(content) { + const data = JSON.parse(content) + if (!Array.isArray(data)) return [] + + return data +} From 423571164c466968b54bfe6843c2130f482b58d8 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 5 Mar 2022 22:48:36 +0300 Subject: [PATCH 2/4] Create kan.org.il.test.js --- sites/kan.org.il/kan.org.il.test.js | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 sites/kan.org.il/kan.org.il.test.js diff --git a/sites/kan.org.il/kan.org.il.test.js b/sites/kan.org.il/kan.org.il.test.js new file mode 100644 index 00000000..e4e9d4fb --- /dev/null +++ b/sites/kan.org.il/kan.org.il.test.js @@ -0,0 +1,47 @@ +// npx epg-grabber --config=sites/kan.org.il/kan.org.il.config.js --channels=sites/kan.org.il/kan.org.il_il.channels.xml --output=guide.xml --days=2 + +const { parser, url } = require('./kan.org.il.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('2022-03-06', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '19', + xmltv_id: 'KANEducational.il' +} + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe( + 'https://www.kan.org.il/tv-guide/tv_guidePrograms.ashx?stationID=19&day=06/03/2022' + ) +}) + +it('can parse response', () => { + const content = `[{"title":"ארץ מולדת - בין תורכיה לבריטניה","start_time":"2022-03-06T00:05:37","end_time":"2022-03-06T00:27:12","id":"2598","age_category_desc":"0","epg_name":"ארץ מולדת","title1":"ארץ מולדת - בין תורכיה לבריטניה","chapter_number":"9","live_desc":"קבוצת תלמידים מתארגנת בפרוץ מלחמת העולם הראשונה להגיש עזרה לישוב. באמצעות התלמידים לומד הצופה על בעיותיו של הישוב בתקופת המלחמה, והתלבטותו בין נאמנות לשלטון העות'מאני לבין תקוותיו מהבריטים הכובשים.","Station_Radio":"0","Station_Id":"20","stationUrlScheme":"kan11://plugin/?type=player&plugin_identifier=kan_player&ds=general-provider%3A%2F%2FfetchData%3Ftype%3DFEED_JSON%26url%3DaHR0cHM6Ly93d3cua2FuLm9yZy5pbC9hcHBLYW4vbGl2ZVN0YXRpb25zLmFzaHg%3D&id=4","program_code":"3671","picture_code":"https://kanweb.blob.core.windows.net/download/pictures/2021/1/20/imgid=45847_Z.jpeg","program_image":"","station_image":"Logo_Image_Logo20_img__8.jpg","program_id":"","timezone":"2"}]` + const result = parser({ content }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2022-03-05T22:05:37.000Z', + stop: '2022-03-05T22:27:12.000Z', + title: 'ארץ מולדת - בין תורכיה לבריטניה', + description: + "קבוצת תלמידים מתארגנת בפרוץ מלחמת העולם הראשונה להגיש עזרה לישוב. באמצעות התלמידים לומד הצופה על בעיותיו של הישוב בתקופת המלחמה, והתלבטותו בין נאמנות לשלטון העות'מאני לבין תקוותיו מהבריטים הכובשים.", + icon: 'https://kanweb.blob.core.windows.net/download/pictures/2021/1/20/imgid=45847_Z.jpeg' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + content: `[]` + }) + expect(result).toMatchObject([]) +}) From 12959d446f0c18edcf16d439c407556bd50dd740 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 5 Mar 2022 22:48:59 +0300 Subject: [PATCH 3/4] Create kan.org.il_il.channels.xml --- sites/kan.org.il/kan.org.il_il.channels.xml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 sites/kan.org.il/kan.org.il_il.channels.xml diff --git a/sites/kan.org.il/kan.org.il_il.channels.xml b/sites/kan.org.il/kan.org.il_il.channels.xml new file mode 100644 index 00000000..44aef68e --- /dev/null +++ b/sites/kan.org.il/kan.org.il_il.channels.xml @@ -0,0 +1,8 @@ + + + + כאן 11 + חינוכית + مكان + + From b79d39e1c66a709f4c9b07b3a0c60aff7006a198 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 5 Mar 2022 22:49:03 +0300 Subject: [PATCH 4/4] Create kan.org.il.yml --- .github/workflows/kan.org.il.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/kan.org.il.yml diff --git a/.github/workflows/kan.org.il.yml b/.github/workflows/kan.org.il.yml new file mode 100644 index 00000000..6cce784f --- /dev/null +++ b/.github/workflows/kan.org.il.yml @@ -0,0 +1,17 @@ +name: allente.se +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: + workflow_run: + workflows: [_trigger] + types: + - completed +jobs: + load: + uses: ./.github/workflows/_load.yml + with: + site: ${{github.workflow}} + secrets: + APP_ID: ${{ secrets.APP_ID }} + APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}