From f67c5a424f3257947a356ae467927909871b1b70 Mon Sep 17 00:00:00 2001 From: eagerterrier Date: Sat, 1 Feb 2025 13:36:17 +0000 Subject: [PATCH] initial commit --- .github/workflows/run-api-integration.yml | 43 ++++++++++++++ .gitignore | 2 + index.js | 72 +++++++++++++++++++++++ package-lock.json | 54 +++++++++++++++++ package.json | 5 ++ readme.md | 49 +++++++++++++++ 6 files changed, 225 insertions(+) create mode 100644 .github/workflows/run-api-integration.yml create mode 100644 .gitignore create mode 100644 index.js create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 readme.md diff --git a/.github/workflows/run-api-integration.yml b/.github/workflows/run-api-integration.yml new file mode 100644 index 0000000..9ae8332 --- /dev/null +++ b/.github/workflows/run-api-integration.yml @@ -0,0 +1,43 @@ +name: Run index and save results + +on: + workflow_dispatch: + schedule: + - cron: '*/30 * * * *' + push: + branches: + - main + +permissions: + contents: write + +jobs: + run-fetchdata: + runs-on: ubuntu-latest + + steps: + - name: Check out the repository + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install dependencies + run: npm install + + - name: Run index script + run: node index.js + + - name: Commit readme files + id: commit + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + if ! git diff --exit-code; then + git add . + git commit -m "Update feeds" + git push + fi + shell: bash diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..03e05e4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +/node_modules diff --git a/index.js b/index.js new file mode 100644 index 0000000..7f3d34d --- /dev/null +++ b/index.js @@ -0,0 +1,72 @@ +const Parser = require('rss-parser'); +const fs = require('fs'); + +const feeds = { + 'afaanoromoo': { title: 'afaanoromoo', url: 'https://feeds.bbci.co.uk/afaanoromoo/rss.xml' }, + 'amharic': { title: 'amharic', url: 'https://feeds.bbci.co.uk/amharic/rss.xml' }, + 'afrique': { title: 'afrique', url: 'https://feeds.bbci.co.uk/afrique/rss.xml' }, + 'hausa': { title: 'hausa', url: 'https://feeds.bbci.co.uk/hausa/rss.xml' }, + 'igbo': { title: 'igbo', url: 'https://feeds.bbci.co.uk/igbo/rss.xml' }, + 'gahuza': { title: 'gahuza', url: 'https://feeds.bbci.co.uk/gahuza/rss.xml' }, + 'pidgin': { title: 'pidgin', url: 'https://feeds.bbci.co.uk/pidgin/rss.xml' }, + 'somali': { title: 'somali', url: 'https://feeds.bbci.co.uk/somali/rss.xml' }, + 'swahili': { title: 'swahili', url: 'https://feeds.bbci.co.uk/swahili/rss.xml' }, + 'tigrinya': { title: 'tigrinya', url: 'https://feeds.bbci.co.uk/tigrinya/rss.xml' }, + 'yoruba': { title: 'yoruba', url: 'https://feeds.bbci.co.uk/yoruba/rss.xml' }, + 'kyrgyz': { title: 'kyrgyz', url: 'https://feeds.bbci.co.uk/kyrgyz/rss.xml' }, + 'uzbek': { title: 'uzbek', url: 'https://feeds.bbci.co.uk/uzbek/rss.xml' }, + 'burmese': { title: 'burmese', url: 'https://feeds.bbci.co.uk/burmese/rss.xml' }, + 'zhongwen-simp': { title: 'zhongwen', url: 'https://feeds.bbci.co.uk/zhongwen/simp/rss.xml' }, + 'zhongwen-trad': { title: 'zhongwen', url: 'https://feeds.bbci.co.uk/zhongwen/trad/rss.xml' }, + 'indonesia': { title: 'indonesia', url: 'https://feeds.bbci.co.uk/indonesia/rss.xml' }, + 'japanese': { title: 'japanese', url: 'https://feeds.bbci.co.uk/japanese/rss.xml' }, + 'korean': { title: 'korean', url: 'https://feeds.bbci.co.uk/korean/rss.xml' }, + 'thai': { title: 'thai', url: 'https://feeds.bbci.co.uk/thai/rss.xml' }, + 'vietnamese': { title: 'vietnamese', url: 'https://feeds.bbci.co.uk/vietnamese/rss.xml' }, + 'bengali': { title: 'bengali', url: 'https://feeds.bbci.co.uk/bengali/rss.xml' }, + 'gujarati': { title: 'gujarati', url: 'https://feeds.bbci.co.uk/gujarati/rss.xml' }, + 'hindi': { title: 'hindi', url: 'https://feeds.bbci.co.uk/hindi/rss.xml' }, + 'marathi': { title: 'marathi', url: 'https://feeds.bbci.co.uk/marathi/rss.xml' }, + 'nepali': { title: 'nepali', url: 'https://feeds.bbci.co.uk/nepali/rss.xml' }, + 'pashto': { title: 'pashto', url: 'https://feeds.bbci.co.uk/pashto/rss.xml' }, + 'punjabi': { title: 'punjabi', url: 'https://feeds.bbci.co.uk/punjabi/rss.xml' }, + 'sinhala': { title: 'sinhala', url: 'https://feeds.bbci.co.uk/sinhala/rss.xml' }, + 'tamil': { title: 'tamil', url: 'https://feeds.bbci.co.uk/tamil/rss.xml' }, + 'telugu': { title: 'telugu', url: 'https://feeds.bbci.co.uk/telugu/rss.xml' }, + 'urdu': { title: 'urdu', url: 'https://feeds.bbci.co.uk/urdu/rss.xml' }, + 'azeri': { title: 'azeri', url: 'https://feeds.bbci.co.uk/azeri/rss.xml' }, + 'russian': { title: 'russian', url: 'https://feeds.bbci.co.uk/russian/rss.xml' }, + 'serbian-lat': { title: 'serbian', url: 'https://feeds.bbci.co.uk/serbian/lat/rss.xml' }, + 'serbian-cyr': { title: 'serbian', url: 'https://feeds.bbci.co.uk/serbian/cyr/rss.xml' }, + 'turkce': { title: 'turkce', url: 'https://feeds.bbci.co.uk/turkce/rss.xml' }, + 'ukrainian': { title: 'ukrainian', url: 'https://feeds.bbci.co.uk/ukrainian/rss.xml' }, + 'portuguese': { title: 'portuguese', url: 'https://feeds.bbci.co.uk/portuguese/rss.xml' }, + 'mundo': { title: 'mundo', url: 'https://feeds.bbci.co.uk/mundo/rss.xml' }, + 'arabic': { title: 'arabic', url: 'https://feeds.bbci.co.uk/arabic/rss.xml' }, + 'persian': { title: 'persian', url: 'https://feeds.bbci.co.uk/persian/rss.xml' }, +}; + + +let parser = new Parser({ + customFields: { + item: [ + ['media:thumbnail', 'mediathumbnail'], + ] + } +}); + +Object.keys(feeds).forEach((service, i) => { + setTimeout( () => { + (async () => { + const url = feeds[service].url; + console.log(`fetching ${url}`); + let feed = await parser.parseURL(url); + let md_contents = `# ${feed.title}\r\r`; + + feed.items.forEach(item => { + md_contents += `## [${item.title}](${item.link})\r![${item.title}](${item.mediathumbnail.$.url})\r\r${item.contentSnippet}\r\r\r`; + }); + fs.writeFileSync(`./${service}.md`, md_contents); + + })()}, 500 * i) +}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..73c1ebc --- /dev/null +++ b/package-lock.json @@ -0,0 +1,54 @@ +{ + "name": "world-service-rss", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "rss-parser": "^3.13.0" + } + }, + "node_modules/entities": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-2.2.0.tgz", + "integrity": "sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==", + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, + "node_modules/rss-parser": { + "version": "3.13.0", + "resolved": "https://registry.npmjs.org/rss-parser/-/rss-parser-3.13.0.tgz", + "integrity": "sha512-7jWUBV5yGN3rqMMj7CZufl/291QAhvrrGpDNE4k/02ZchL0npisiYYqULF71jCEKoIiHvK/Q2e6IkDwPziT7+w==", + "dependencies": { + "entities": "^2.0.3", + "xml2js": "^0.5.0" + } + }, + "node_modules/sax": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.4.1.tgz", + "integrity": "sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==" + }, + "node_modules/xml2js": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.5.0.tgz", + "integrity": "sha512-drPFnkQJik/O+uPKpqSgr22mpuFHqKdbS835iAQrUC73L2F5WkboIRd63ai/2Yg6I1jzifPFKH2NTK+cfglkIA==", + "dependencies": { + "sax": ">=0.6.0", + "xmlbuilder": "~11.0.0" + }, + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/xmlbuilder": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", + "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==", + "engines": { + "node": ">=4.0" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..15aad7b --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "rss-parser": "^3.13.0" + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..b614b16 --- /dev/null +++ b/readme.md @@ -0,0 +1,49 @@ +# BBC World Service RSS Feeds output + +A list of the most recent stories from across the world in your language + +## Feeds + +- [afaanoromoo](./afaanoromoo.md) +- [afrique](./afrique.md) +- [amharic](./amharic.md) +- [arabic](./arabic.md) +- [azeri](./azeri.md) +- [bengali](./bengali.md) +- [burmese](./burmese.md) +- [gahuza](./gahuza.md) +- [gujarati](./gujarati.md) +- [hausa](./hausa.md) +- [hindi](./hindi.md) +- [igbo](./igbo.md) +- [indonesia](./indonesia.md) +- [japanese](./japanese.md) +- [korean](./korean.md) +- [kyrgyz](./kyrgyz.md) +- [marathi](./marathi.md) +- [mundo](./mundo.md) +- [nepali](./nepali.md) +- [pashto](./pashto.md) +- [persian](./persian.md) +- [pidgin](./pidgin.md) +- [portuguese](./portuguese.md) +- [punjabi](./punjabi.md) +- [russian](./russian.md) +- [serbian cyr](./serbian-cyr.md) +- [serbian lat](./serbian-lat.md) +- [sinhala](./sinhala.md) +- [somali](./somali.md) +- [swahili](./swahili.md) +- [tamil](./tamil.md) +- [telugu](./telugu.md) +- [thai](./thai.md) +- [tigrinya](./tigrinya.md) +- [turkce](./turkce.md) +- [ukrainian](./ukrainian.md) +- [urdu](./urdu.md) +- [uzbek](./uzbek.md) +- [vietnamese](./vietnamese.md) +- [yoruba](./yoruba.md) +- [zhongwen simp](./zhongwen-simp.md) +- [zhongwen trad](./zhongwen-trad.md) + \ No newline at end of file