-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathheroStatSeed.js
79 lines (64 loc) · 2.25 KB
/
heroStatSeed.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
This seed file is only a placeholder. It should be expanded and altered
to fit the development of your application.
It uses the same file the server uses to establish
the database connection:
--- server/db/index.js
The name of the database used is set in your environment files:
--- server/env/*
This seed file has a safety check to see if you already have users
in the database. If you are developing multiple applications with the
fsg scaffolding, keep in mind that fsg always uses the same database
name in the environment files.
Refer to the q documentation for why and how q.invoke is used.
*/
//this seeds for a single hero
var mongoose = require('mongoose');
var connectToDb = require('./server/db');
var User = mongoose.model('User');
var HeroStat = mongoose.model('heroStat');
var fs = require('fs');
var cheerio = require('cheerio');
var temp = fs.readFileSync('./heroSpecific.txt').toString();
var _ = require('lodash');
$ = cheerio.load(temp);
//console.log($("a[href^='/heroes/sniper']").first().parents('tr'));
var array = [];
$('tr').each(function(i,elem){
array.push([$(this).find("img").attr('alt'), $(this).find("td").first().next().next().text(), $(this).find("td").first().next().next().next().text(), $(this).find("td").first().next().next().next().next().text()]);
});
array.shift();
console.log("should start here", array);
connectToDb.then(function () {
var results = [];
var obj = {
heroName: 'Abaddon',
statType: 'heroMatchUp',
proficiency: []
};
var tempObj = {};
array.forEach(function (el) {
tempObj = {};
tempObj.name = el[0];
tempObj.advantage = (el[1].replace('\.', '').replace('\%', '')) / 10000;
tempObj.winRate = (el[2].replace('\.', '').replace('\%', '')) / 10000;
tempObj.count = Number(el[3].replace(',', ''));
obj.proficiency.push(tempObj);
});
//fs.writeFile('testSeed2.txt', array, function (err) {
//
//});
console.log('OBJ HERE', obj);
HeroStat.findOne({heroName: 'abaddon'}, function(err, heroData){
_.extend(heroData, obj);
heroData.save(function(err, hero){
console.log('done saving');
});
console.log(heroData);
}).then(function () {
process.kill(0);
}).catch(function (err) {
console.error(err);
process.kill(1);
});
});