-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathosoby.js
More file actions
37 lines (30 loc) · 1019 Bytes
/
osoby.js
File metadata and controls
37 lines (30 loc) · 1019 Bytes
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
var fs = require('fs'),
bot = require('nodemw'),
client = new bot('config.js');
var persons = [];
client.getPagesInCategory('Osoby', function(pages) {
pages.forEach(function(page) {
client.getArticle(page.title, function(content) {
client.expandTemplates(content, page.title, function(tmpl) {
var ur = client.getTemplateParamFromXml(tmpl, 'data_ur') || '',
sm = client.getTemplateParamFromXml(tmpl, 'data_sm') || '';
// pobierz tylko rok + usuń brackety linków
ur = parseInt(ur.split(' ').pop().replace(/\[|\]/g, ''), 10) || false;
sm = parseInt(sm.split(' ').pop().replace(/\[|\]/g, ''), 10) || false;
//console.log('Ur: ' + ur);
//console.log('Sm: ' + sm);
if (ur) {
console.log('* [[' + page.title + ']] (' + ur + '-' + sm + ')');
}
persons.push({
name: page.title,
ur: ur,
sm: sm
});
if (persons.length === pages.length) {
fs.writeFileSync('db/osoby.json', JSON.stringify(persons, null, ' '));
}
});
});
});
});