-
Notifications
You must be signed in to change notification settings - Fork 3
/
scrape-vgpro-hero-synergies.js
60 lines (51 loc) · 1.58 KB
/
scrape-vgpro-hero-synergies.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
var settings = require("./settings.json");
var list_heroes = require(settings['list_of_heroes_json']);
var htmlToJson = require('html-to-json');
var fs = require('fs');
var util = require('util');
var request = require('request');
var url = require("url");
var path = require("path");
var async = require("async");
let list = [];
if (process.argv.length > 2) {
process.argv.forEach(function (val, index, array) {
//console.log(index + ': ' + val);
if (index >= 2) {
list = getDetails(val, function(){ console.log(val + ' yata!'); });
}
});
} else {
async.eachSeries(list_heroes, function iteratee(val, callback) {
getDetails(val['hero'], function(){ console.log(val['hero'] + ' yata!'); callback(); });
});
}
function getDetails(hero_name, cb) {
var list = list_heroes.filter(
function(elem, index, array){
//console.log(elem);
return elem['hero'].toLowerCase() == hero_name.toLowerCase();
});
console.log(list);
if (list.length == 1) {
//var hero_url = settings['main_url'] + list[0]['url']; //vaingloryfire wiki
var hero_url = settings['vgpro_api_url'] + list[0]['hero'];
console.log(hero_url);
var url = hero_url;
var filename = settings['local_images_path'] + list[0]['hero'].toLowerCase() + '-synergies.json';
//var cb = function(){ console.log(list[0]['hero'] + ' yata!');}
var options = {
url: url,
headers: {
'User-Agent': 'request'
}
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
fs.writeFileSync(filename, body, 'utf-8');
cb();
}
}
request(options, callback);
}
}