Skip to content

Commit f039c48

Browse files
author
Zakaria RACHEDI
committed
Pets fully supported
1 parent fef31ed commit f039c48

File tree

4 files changed

+90
-17
lines changed

4 files changed

+90
-17
lines changed

lib/cli-view/cmd.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,7 @@ var weapon = [
5656
}
5757
];
5858

59-
var set = [
60-
{
61-
type: 'input',
62-
name: 'pages',
63-
message: 'How many page do you want de crawl ?',
64-
default: '1',
65-
validate: function(value) {
66-
var valid = !isNaN(parseFloat(value));
67-
return valid || 'Please enter a number';
68-
},
69-
filter: Number
70-
}
71-
];
72-
73-
var mount = [
59+
var page = [
7460
{
7561
type: 'input',
7662
name: 'pages',
@@ -106,6 +92,9 @@ function switchCategory(category) {
10692
case 'mount':
10793
return categoryMount();
10894
break;
95+
case 'pet':
96+
return categoryPet();
97+
break;
10998
default:
11099
console.log('Sorry, we are out of ' + category + '.');
111100
}
@@ -131,7 +120,7 @@ function categoryWeapon() {
131120

132121
function categorySet() {
133122
return new Promise(function(resolve, reject) {
134-
inquirer.prompt(set).then(answers => {
123+
inquirer.prompt(page).then(answers => {
135124
answers.category = 'set';
136125
var category = JSON.stringify(answers, null, ' ');
137126
resolve(category);
@@ -141,10 +130,20 @@ function categorySet() {
141130

142131
function categoryMount() {
143132
return new Promise(function(resolve, reject) {
144-
inquirer.prompt(mount).then(answers => {
133+
inquirer.prompt(page).then(answers => {
145134
answers.category = 'mount';
146135
var category = JSON.stringify(answers, null, ' ');
147136
resolve(category);
148137
});
149138
});
139+
}
140+
141+
function categoryPet() {
142+
return new Promise(function(resolve, reject) {
143+
inquirer.prompt(page).then(answers => {
144+
answers.category = 'pet';
145+
var category = JSON.stringify(answers, null, ' ');
146+
resolve(category);
147+
});
148+
});
150149
}

lib/cli-view/cmdSwitch.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ var cmdSwitch = exports.cmdSwitch = function(category) {
8181
case 'mount':
8282
url = 'http://www.dofus-touch.com/fr/mmorpg/encyclopedie/montures?';
8383
break;
84+
case 'pet':
85+
url = 'http://www.dofus-touch.com/fr/mmorpg/encyclopedie/familiers?';
86+
break;
8487
default:
8588
console.log('Sorry, we are out of ' + category + '.');
8689
}

lib/getItems.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var ge = require('./item-crawler/getEquipments');
44
var gw = require('./item-crawler/getWeapons');
55
var gs = require('./item-crawler/getSets');
66
var gm = require('./item-crawler/getMounts');
7+
var gp = require('./item-crawler/getPets');
78
var Nightmare = require('nightmare');
89
var nightmare = new Nightmare();
910

@@ -55,6 +56,12 @@ function getData(url, back, callback) {
5556
case /\bmontures\b/gi.test(url):
5657
categoryPromise = gm.getMounts(url);
5758
break;
59+
case /\bpets\b/gi.test(url):
60+
categoryPromise = gp.getPets(url);
61+
break;
62+
case /\bfamiliers\b/gi.test(url):
63+
categoryPromise = gp.getPets(url);
64+
break;
5865
default:
5966
console.log('Sorry, we are out of ' + url + '.');
6067
}

lib/item-crawler/getPets.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
var Nightmare = require('nightmare');
2+
var nightmare = new Nightmare();
3+
4+
var getPets = exports.getPets = function (url) {
5+
return new Promise(function(resolve, reject) {
6+
nightmare
7+
.goto(url)
8+
.inject('js', 'node_modules/jquery/dist/jquery.min.js')
9+
.evaluate(function () {
10+
try {
11+
var itemId = document.URL.replace(/\D/g,'');
12+
var type = $('div.ak-encyclo-detail-right.ak-nocontentpadding').find('div.ak-encyclo-detail-type.col-xs-6').find('span').text().trim();
13+
var name = $('h1.ak-return-link').text().trim();
14+
var description = $('div.ak-encyclo-detail-right.ak-nocontentpadding').find('div.ak-container.ak-panel:first').find('div.ak-panel-content').text().trim();
15+
var lvl = $('div.ak-encyclo-detail-right.ak-nocontentpadding').find('div.ak-encyclo-detail-level.col-xs-6.text-right').text().trim().replace(/\D/g,'');
16+
var imgUrl = $('div.ak-encyclo-detail-illu').find('img').attr('src').replace('dofus/ng/img/../../../', '');
17+
18+
var item = {
19+
id: itemId,
20+
name: name,
21+
description: description,
22+
lvl: lvl,
23+
type: type,
24+
imgUrl: imgUrl,
25+
url: document.URL
26+
}
27+
28+
item["stats"] = [];
29+
item["condition"] = [];
30+
item["maxstats"] = [];
31+
32+
if ($('div.ak-encyclo-detail-right.ak-nocontentpadding').find('div.col-sm-6').eq(1).find('div.ak-container.ak-panel.no-padding').eq(1).text() !== '') {
33+
$('div.ak-encyclo-detail-right.ak-nocontentpadding').find('div.col-sm-6').eq(1).find('div.ak-container.ak-panel.no-padding').eq(0).find('div.ak-list-element').each(function(i, element){
34+
var condition = $(this).find( "div.ak-title" ).remove("br").text().trim();
35+
item["condition"].push(condition);
36+
});
37+
$('div.ak-encyclo-detail-right.ak-nocontentpadding').find('div.col-sm-6').eq(1).find('div.ak-container.ak-panel.no-padding').eq(1).find('div.ak-list-element').each(function(i, element){
38+
var maxstats = $(this).find( "div.ak-title" ).text().trim();
39+
item["maxstats"].push(maxstats);
40+
});
41+
}else {
42+
$('div.ak-encyclo-detail-right.ak-nocontentpadding').find('div.col-sm-6').eq(1).find('div.ak-container.ak-panel.no-padding').eq(0).find('div.ak-list-element').each(function(i, element){
43+
var maxstats = $(this).find( "div.ak-title" ).text().trim();
44+
item["maxstats"].push(maxstats);
45+
});
46+
}
47+
48+
49+
$('div.ak-encyclo-detail-right.ak-nocontentpadding').find('div.col-sm-6').eq(0).find('div.ak-list-element').each(function(i, element){
50+
var stat = $(this).find( "div.ak-title" ).text().trim();
51+
item["stats"].push(stat);
52+
});
53+
54+
return item;
55+
} catch(err){
56+
return [err];
57+
}
58+
})
59+
.then((htmlRes) => {
60+
console.log(htmlRes);
61+
resolve(htmlRes);
62+
});
63+
});
64+
}

0 commit comments

Comments
 (0)