-
Notifications
You must be signed in to change notification settings - Fork 0
/
runquery.js
63 lines (47 loc) · 1.42 KB
/
runquery.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
https://web.archive.org/web/http://nonbinary.org:80/w/index.php?title=Transgender&action=edit
This script operates on 2/list.json and tries to query archive.org for wiki text.
*/
var request = require('request');
var fs = require('fs');
var pages = require('./2/list.json');
var times = require('./2/times.json');
var failed = [];
var complete = 0;
function urlForPage(name, time) {
if(time === undefined){
time = '2016';
}
return 'https://web.archive.org/web/' + time + '/http://nonbinary.org:80/w/index.php?title=' + name + '&action=edit';
}
function addFailed(name) {
failed.push(name);
fs.writeFile('3/failed.json', JSON.stringify(failed));
}
function oneComplete() {
complete++;
console.log(complete + '/' + pages.length);
}
var index = 0;
//FIXME This will never finish execution FYI
setInterval(function () {
var name = pages[index];
var time = times[index];
if(!fs.existsSync('3/pages/' + name + '.txt')) {
request(urlForPage(name, time), function (error, response, body) {
var res = /<textarea ([\S\s]*)>([\S\s]*)<\/textarea>/g.exec(body);
if (res !== null) {
fs.writeFile('3/pages/' + name + '.txt', res[2]);
}
else {
addFailed(name);
}
console.log(name);
oneComplete();
});
}
else{
oneComplete();
}
index++;
}, 1000);