-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
84 lines (78 loc) · 5.23 KB
/
Copy pathindex.js
File metadata and controls
84 lines (78 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const Parser = require('rss-parser');
const fs = require('fs');
const feeds = {
'afaanoromoo': { title: 'afaanoromoo', url: 'https://feeds.bbci.co.uk/afaanoromoo/rss.xml', locale: 'om-ET' },
'amharic': { title: 'amharic', url: 'https://feeds.bbci.co.uk/amharic/rss.xml', locale: 'am-ET' },
'afrique': { title: 'afrique', url: 'https://feeds.bbci.co.uk/afrique/rss.xml', locale: 'fr' },
'hausa': { title: 'hausa', url: 'https://feeds.bbci.co.uk/hausa/rss.xml', locale: 'ha-GH' },
'igbo': { title: 'igbo', url: 'https://feeds.bbci.co.uk/igbo/rss.xml', locale: 'ig' },
'gahuza': { title: 'gahuza', url: 'https://feeds.bbci.co.uk/gahuza/rss.xml', locale: 'rw-RW' },
'pidgin': { title: 'pidgin', url: 'https://feeds.bbci.co.uk/pidgin/rss.xml', locale: 'pcm' },
'somali': { title: 'somali', url: 'https://feeds.bbci.co.uk/somali/rss.xml', locale: 'so-SO' },
'swahili': { title: 'swahili', url: 'https://feeds.bbci.co.uk/swahili/rss.xml', locale: 'sw-KE' },
'tigrinya': { title: 'tigrinya', url: 'https://feeds.bbci.co.uk/tigrinya/rss.xml', locale: 'ti-ET' },
'yoruba': { title: 'yoruba', url: 'https://feeds.bbci.co.uk/yoruba/rss.xml', locale: 'yo' },
'kyrgyz': { title: 'kyrgyz', url: 'https://feeds.bbci.co.uk/kyrgyz/rss.xml', locale: 'ky-KG' },
'uzbek': { title: 'uzbek', url: 'https://feeds.bbci.co.uk/uzbek/cyr/rss.xml', locale: 'uz-UZ' },
'burmese': { title: 'burmese', url: 'https://feeds.bbci.co.uk/burmese/rss.xml', locale: 'my-MM' },
'zhongwen-trad': { title: 'zhongwen', url: 'https://feeds.bbci.co.uk/zhongwen/trad/rss.xml', locale: 'zh-hant' },
'indonesia': { title: 'indonesia', url: 'https://feeds.bbci.co.uk/indonesia/rss.xml', locale: 'id-ID' },
'japanese': { title: 'japanese', url: 'https://feeds.bbci.co.uk/japanese/rss.xml', locale: 'ja-JP' },
'korean': { title: 'korean', url: 'https://feeds.bbci.co.uk/korean/rss.xml', locale: 'ko-KO' },
'thai': { title: 'thai', url: 'https://feeds.bbci.co.uk/thai/rss.xml', locale: 'th-TH' },
'vietnamese': { title: 'vietnamese', url: 'https://feeds.bbci.co.uk/vietnamese/rss.xml', locale: 'vi-VN' },
'bengali': { title: 'bengali', url: 'https://feeds.bbci.co.uk/bengali/rss.xml', locale: 'bn-BD' },
'gujarati': { title: 'gujarati', url: 'https://feeds.bbci.co.uk/gujarati/rss.xml', locale: 'gu-IN' },
'hindi': { title: 'hindi', url: 'https://feeds.bbci.co.uk/hindi/rss.xml', locale: 'hi-IN' },
'marathi': { title: 'marathi', url: 'https://feeds.bbci.co.uk/marathi/rss.xml', locale: 'mr-IN' },
'nepali': { title: 'nepali', url: 'https://feeds.bbci.co.uk/nepali/rss.xml', locale: 'ne-NP' },
'pashto': { title: 'pashto', url: 'https://feeds.bbci.co.uk/pashto/rss.xml', locale: 'ps' },
'punjabi': { title: 'punjabi', url: 'https://feeds.bbci.co.uk/punjabi/rss.xml', locale: 'pa-IN' },
'sinhala': { title: 'sinhala', url: 'https://feeds.bbci.co.uk/sinhala/rss.xml', locale: 'si-LK' },
'tamil': { title: 'tamil', url: 'https://feeds.bbci.co.uk/tamil/rss.xml', locale: 'ta-IN' },
'telugu': { title: 'telugu', url: 'https://feeds.bbci.co.uk/telugu/rss.xml', locale: 'te-IN' },
'urdu': { title: 'urdu', url: 'https://feeds.bbci.co.uk/urdu/rss.xml', locale: 'ur' },
'azeri': { title: 'azeri', url: 'https://feeds.bbci.co.uk/azeri/rss.xml', locale: 'az-AZ' },
'russian': { title: 'russian', url: 'https://feeds.bbci.co.uk/russian/rss.xml', locale: 'ru-RU' },
'serbian-lat': { title: 'serbian', url: 'https://feeds.bbci.co.uk/serbian/lat/rss.xml', locale: 'sr-latn' },
'turkce': { title: 'turkce', url: 'https://feeds.bbci.co.uk/turkce/rss.xml', locale: 'tr-TR' },
'ukrainian': { title: 'ukrainian', url: 'https://feeds.bbci.co.uk/ukrainian/rss.xml', locale: 'uk-UA' },
'portuguese': { title: 'portuguese', url: 'https://feeds.bbci.co.uk/portuguese/rss.xml', locale: 'pt-BR' },
'mundo': { title: 'mundo', url: 'https://feeds.bbci.co.uk/mundo/rss.xml', locale: 'es-005' },
'arabic': { title: 'arabic', url: 'https://feeds.bbci.co.uk/arabic/rss.xml', locale: 'ar' },
'persian': { title: 'persian', url: 'https://feeds.bbci.co.uk/persian/rss.xml', locale: 'fa' },
};
let parser = new Parser({
customFields: {
item: [
['media:thumbnail', 'mediathumbnail'],
]
}
});
const options = {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
};
return Object.keys(feeds).forEach(async (service, i) => {
await 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 => {
const dateOriginal = new Date(item.pubDate);
const mediathumbnail = item.mediathumbnail ? item.mediathumbnail.$.url : '';
const date = item.pubDate ? dateOriginal.toLocaleDateString(feeds[service].locale, options) : '';
md_contents += `## [${item.title}](${item.link}?at_campaign=githubrss)\r\r\r_${date}_\r\r${item.contentSnippet}\r\r\r`;
});
console.log(`writing ${service}`);
return fs.writeFileSync(`./${service}.md`, md_contents);
})()
}, 500 * i)
});