Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Commit

Permalink
Add page encoding detection
Browse files Browse the repository at this point in the history
  • Loading branch information
alexnault committed May 24, 2015
1 parent 2314e8e commit 8fa8153
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/projection.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use strict';

var request = require('request'),
var _ = require('underscore'),
request = require('request'),
cheerio = require('cheerio'),
qs = require('query-string'),
_ = require('underscore'),
iconv = require('iconv-lite'),
charset = require('charset'),
Cache = require('./cache');

// var Projection = function()
// var Projection = function()
function Projection() {
this.GOOGLE_ENDPOINT = 'http://www.google.com/movies';
this._cache = new Cache(10);
Expand All @@ -25,14 +27,15 @@ Projection.prototype.findTheaters = function(near, options, callback) {
return;
}

request(url, function (err, res, body) {
request({uri: url, method: 'GET', encoding: null}, function (err, res, body) {
err = errorCheck(err, res);
if (err) {
callback(err);
return;
}

var $ = cheerio.load(body);
var encoding = charset(res.headers, body);
var $ = cheerio.load(iconv.decode(new Buffer(body), encoding));

// List of theaters returned
var theaters = [];
Expand Down Expand Up @@ -95,14 +98,15 @@ Projection.prototype.findMovie = function(near, movie, options, callback) {
return;
}

request(url, function (err, res, body) {
request({uri: url, method: 'GET', encoding: null}, function (err, res, body) {
err = errorCheck(err, res);
if (err) {
callback(err);
return;
}

var $ = cheerio.load(body);
var encoding = charset(res.headers, body);
var $ = cheerio.load(iconv.decode(new Buffer(body), encoding));

var m = $('.movie');

Expand Down Expand Up @@ -211,14 +215,12 @@ function formatShowtimes(showtimes) {
});
};

var p = new Projection();
// p.findTheaters('Sherbrooke', {}, function(err, theaters) {
// var p = new Projection();
// p.findTheaters('Sherbrooke', { hl:'ru'}, function(err, theaters) {
// console.log(theaters[2].movies[0]);
// });
// p.findMovie('Sherbrooke', 'Mad Max', { hl:'fr'}, function(err, movie) {
// p.findMovie('Sherbrooke', 'Mad Max', { hl:'fr'}, function(err, movie) {
// //console.log(movie);
// });
// p.findMovie('Sherbrooke', 'Mad Max', { hl:'ru'}, function(err, movie) {
// console.log(movie);
// });

module.exports = Projection;
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
],
"author": "anault",
"dependencies": {
"charset": "^1.0.0",
"cheerio": "0.19.0",
"iconv-lite": "^0.4.9",
"query-string": "^2.1.0",
"request": "2.55.0",
"underscore": "^1.8.3"
Expand Down

0 comments on commit 8fa8153

Please sign in to comment.