-
Notifications
You must be signed in to change notification settings - Fork 0
/
strength.js
79 lines (62 loc) · 1.56 KB
/
strength.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
'use strict';
var data = require('./data');
var utils = require('./utils');
var CONSTANTS = require('./constants');
var username = CONSTANTS.username;
var password = CONSTANTS.password;
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: false });
var url = 'http://symmetricstrength.com/lifter/wisamjs';
var fs = require('fs');
nightmare
.goto(url)
.select('select#form-rep-max', 5)
.wait(1000)
.evaluate(function () {
var levels = [];
var exercises = [];
var standards = [];
document.querySelectorAll('thead th')
.forEach(function(level, levelId) {
if(levelId) {
var levelName = level.textContent;
levels.push({
name: levelName,
id: levelId - 1
})
}
document.querySelectorAll('tbody tr')
.forEach(function(row, exerciseId) {
if (!exercises[exerciseId]){
var exerciseName = row.querySelector('td').textContent.replace(/[ \t]+$/g,'');
exercises.push({
name: exerciseName,
id: exerciseId
})
}
weightForExercise = row.querySelectorAll('td')
.forEach(function(weight,i) {
if (i && levelId === i) {
standard = weight.textContent;
standards.push({
standard: standard,
levelId: levelId,
exerciseId: exerciseId
})
}
})
});
})
return {
levels: levels,
exercises: exercises,
standards: standards
}
})
.end()
.then(function (result) {
fs.writeFile('strength.json', JSON.stringify(result, null, '\t'), 'utf8');
})
.catch(function (error) {
console.error('Error:', error);
});