Skip to content

Commit

Permalink
update deps, fix getTicks
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderpick committed Feb 18, 2017
1 parent 620b654 commit cccec37
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 48 deletions.
30 changes: 17 additions & 13 deletions lib/27crags.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Functionality for indexing content for search.

var _ = require('underscore');
_.mixin(require('underscore.string'));
var _s = require('underscore.string');
var util = require('util');
var Step = require('step');
var cheerio = require('cheerio');
Expand Down Expand Up @@ -45,7 +45,7 @@ function format(str) {
str = str.replace(/\\/g, '').trim();
if (str.length > 3) str = str.toLowerCase();
return _.map(str.split(' '), function (w) {
return _.capitalize(w);
return _s.capitalize(w);
}).join(' ');
}

Expand Down Expand Up @@ -131,24 +131,29 @@ var boulderMap = [
];

var createTickObj = function($, els) {

var grade = _s.trim($(els.get(5)).find('.grade').text())
if (grade === '') {
grade = _s.trim($(els.get(5)).text())
}

var obj = {
date: moment($(els.get(0)), 'YYYY-MM-DD'),
sent: true,
style: styleMap[$(els.get(8)).text()],
ascent: _.trim(format($(els.get(1)).find('a').text())),
style: styleMap[_s.trim($(els.get(6)).find('.ascent-type').text())],
ascent: _s.trim(format($($(els.get(2)).find('a').get(0)).text())),
recommended: false,
crag: _.trim(format($(els.get(2)).find('a').text())),
crag: _s.trim(format($(els.get(3)).find('a').text())),
cragCountry: null,
cragCity: null,
ascentSector: null,
first: $(els.get(7)).text().indexOf('FA') !== -1,
first: $(els.get(6)).text().indexOf('FA') !== -1,
feel: null,
secondGo: null,
note: $(els.get(9)).text(),
rating: $(els.get(6)).find('.full').length,
type: $(els.get(3)).text().indexOf('Boulder') !== -1 ? 'b' : 'r',
// Remove + and - from the V grades
grade: $(els.get(4)).text().replace(/[+-]/g, '')
note: _s.trim($(els.get(2)).find('.ascent-details').text()),
rating: $(els.get(2)).find('.stars').children().length,
type: $(els.get(4)).text().indexOf('Boulder') !== -1 ? 'b' : 'r',
grade: grade
}

// Try to map to Island's crag names
Expand Down Expand Up @@ -177,7 +182,6 @@ var createTickObj = function($, els) {
}

return obj;

}

// Searches for a username, and if exists, returns the username with geo
Expand Down Expand Up @@ -294,7 +298,7 @@ exports.scrapeCrags = function(start, end, cb) {

var $ = cheerio.load(body);

// I had to serialize all the crag requests to not overwhelm 27crags,
// I had to serialize all the crag requests to not overwhelm 27crags,
// so this is quick and dirty way to do that
var rows = $('table').find('tr:not(:has(th))');
var len = rows.length;
Expand Down
27 changes: 15 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@
"private": true,
"author": "The Island (git://github.com/The-Island)",
"name": "island-lib27crags",
"version": "0.0.1",
"version": "0.0.2",
"repository": {
"type": "git",
"url": "git://github.com/Islandio/island-lib27crags.git"
},
"main": "lib/27crags",
"dependencies": {
"async": "^1.3.0",
"cheerio": "^0.18.0",
"csv-parse": "^0.1.3",
"json2csv": "^2.4.1",
"moment": "^2.8.4",
"request": "^2.58.0",
"step": "0.0.5",
"underscore": "^1.4.4",
"underscore.string": "~2.3.1"
"async": "~2.1.4",
"csv-parse": "^1.2.0",
"json2csv": "^3.7.3",
"cheerio": "^0.22.0",
"moment": "^2.17.1",
"request": "~2.79.0",
"step": "1.0.0",
"underscore": "~1.8.3",
"underscore.string": "~3.3.4"
},
"engines": {
"node": "~0.10.26"
"devDependencies": {
"mocha": "^3.2.0"
},
"scripts": {
"test": "mocha"
}
}
10 changes: 5 additions & 5 deletions scripts/crag_add_missing.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var lib27crags = require('../lib/27crags');
var fs = require('fs');
var request = require('request');
var _ = require('underscore');
_.mixin(require('underscore.string'));
var _s = require('underscore.string');
var Step = require('Step');
var csvParse = require('csv-parse');
var json2csv = require('json2csv');
Expand All @@ -29,7 +29,7 @@ Step(
fs.readFile(file, this);
},
// Parse CSV
function (err, csv) {
function (err, csv) {
if (err) return this(err);
csvParse(csv, this);
},
Expand Down Expand Up @@ -107,18 +107,18 @@ Step(
}, this);
},
function (err, data) {
if (err) return this(err);
if (err) return this(err);
var newFile = file.split('.csv')[0] + '_new.csv';
var csv = _.map(data, function(d) {
d = _.map(d, function(el) {
if (el && el.indexOf(',') !== -1) {
el = '\"' + el + '\"';
}
}
return el;
});
return d.toString();
});
csv = csv.join('\n');
csv = csv.join('\n');
console.log('Added ' + counter + ' crags to Island');
console.log('Writing to ' + newFile);
fs.writeFile(newFile, csv, this);
Expand Down
2 changes: 1 addition & 1 deletion scripts/crag_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var lib27crags = require('../lib/27crags');
var fs = require('fs');
var request = require('request');
var _ = require('underscore');
_.mixin(require('underscore.string'));
var _s = require('underscore.string');
var Step = require('Step');

var file = process.argv[2];
Expand Down
2 changes: 1 addition & 1 deletion scripts/crag_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var lib27crags = require('../lib/27crags');
var fs = require('fs');
var request = require('request');
var _ = require('underscore');
_.mixin(require('underscore.string'));
var _s = require('underscore.string');
var Step = require('Step');
var json2csv = require('json2csv');

Expand Down
1 change: 0 additions & 1 deletion scripts/crag_scraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ lib27crags.scrapeCrags(start, end, function(err, res) {
});
});
});

28 changes: 28 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var lib27crags = require('../lib/27crags');
var assert = require('assert');

describe('island-27crags', function() {
this.timeout(10000);
var userId;
describe('#searchUser()', function() {
it('should find the user', function(done) {
lib27crags.searchUser('Paul Robinson', function(err, res) {
if (err) done(err);
assert.ok(res.length > 0)
assert.equal(res[0].name, 'Paul Robinson')
userId = res[0].userId
done()
});
});
});

describe('#getTicks()', function() {
it('should get the user\'s ticks', function(done) {
lib27crags.getTicks(userId, function(err, res) {
if (err) done(err);
assert.ok(res.length > 0)
done()
});
});
});
});
15 changes: 0 additions & 15 deletions tests/test.js

This file was deleted.

0 comments on commit cccec37

Please sign in to comment.