-
Notifications
You must be signed in to change notification settings - Fork 1
/
bramy_festung.js
49 lines (36 loc) · 1.28 KB
/
bramy_festung.js
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
var fs = require('fs'),
bot = require('nodemw'),
client = new bot('config.js');
var fromRegExp = /<part><name>zbudowana\s*<\/name>=<value>([^>]+)<\/value>/,
toRegExp = /<part><name>zburzona\s*<\/name>=<value>([^>]+)<\/value>/;
var items = [];
client.getPagesInCategory('Twierdza Poznań', function(pages) {
var n = 0;
pages.forEach(function(page) {
if (!page.title.match(/^Brama|Furta/) || page.ns != 0) return;
n++;
client.getArticle(page.title, function(content) {
client.expandTemplates(content, page.title, function(tmpl) {
//console.log('\n\n==' + page.title + '==');
//console.log(tmpl);
var from = tmpl.match(fromRegExp),
to = tmpl.match(toRegExp);
from = from && from[1].trim() || '';
to = to && to[1].trim() || '';
// pobierz tylko rok + usuń brackety linków
from = parseInt(from.split('-').shift().replace(/\[|\]|ok\./g, ''), 10) || '';
to = parseInt(to.split('-').shift().replace(/\[|\]|ok\./g, ''), 10) || '';
//console.log([from, to]);
console.log('* [[' + page.title + ']] (' + from + '-' + to + ')');
items.push({
name: page.title,
from: from,
to: to
});
if (items.length === n) {
fs.writeFileSync('db/bramy_festung.json', JSON.stringify(items));
}
});
});
});
});