Skip to content

Commit

Permalink
Send the right cookies for 27crags
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalcohen committed Jul 13, 2015
1 parent 313aa2b commit 620b654
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/27crags.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ var fs = require('fs');
// A csv file with column 'name' and column 'islandCrag'
var resource = __dirname + '/../resources/27crags_to_island_map.csv';

// Setup a cookie to deal with 27crags splash page money grab
var j = request.jar();
j.setCookie(request.cookie('campaign_seen=1'), 'http://27crags.com');
j.setCookie(request.cookie('campaign_history=1'), 'http://27crags.com');

cragMap = {};

fs.readFile(resource, function(err, csv) {
Expand Down Expand Up @@ -180,10 +185,6 @@ exports.searchUser= function(name, cb) {

var searchResults = [];

var j = request.jar();
var cookie = request.cookie('campaign_seen=1');
j.setCookie(cookie, 'http://www.27crags.com');

// Get Htmls
request.get({
uri: 'http://www.27crags.com/site/search',
Expand Down Expand Up @@ -238,15 +239,17 @@ exports.getTicks = function(userId, cb) {
request.get({
uri: urls.ascentUrl,
headers: headers,
encoding: 'utf8'
encoding: 'utf8',
jar: j
}, this.parallel());

// 27crags hides additional data behind an AJAX request to this
// URL
request.get({
uri: urls.moreUrl,
headers: _.extend(headers, {'X-Requested-With': 'XMLHttpRequest'}),
encoding: 'utf8'
encoding: 'utf8',
jar: j
}, this.parallel());

},
Expand Down Expand Up @@ -280,7 +283,8 @@ exports.scrapeCrags = function(start, end, cb) {
request.get({
uri: 'http://www.27crags.com/crags/all/descending/by/favourite_count/page/' + number,
headers: headers,
encoding: 'utf8'
encoding: 'utf8',
jar: j
}, this);
},
function requestEachCrag(err, resp, body) {
Expand All @@ -305,6 +309,7 @@ exports.scrapeCrags = function(start, end, cb) {
uri: 'http://www.27crags.com/' + $a.attr('href'),
headers: headers,
encoding: 'utf8',
jar: j
}, function(err, res) {
cbs[idx](err, res);
idx++;
Expand Down
2 changes: 2 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

var lib27crags = require('../lib/27crags');

/*
lib27crags.searchUser('bill', function(err, res) {
console.log(err, res);
});
*/

lib27crags.getTicks('wmmurray', function(err, res) {
//console.log(err, res.length);
Expand Down

0 comments on commit 620b654

Please sign in to comment.