Skip to content

Commit

Permalink
Set up code for Liam to write test
Browse files Browse the repository at this point in the history
  • Loading branch information
snakecharmer1024 committed Oct 4, 2015
1 parent b42204a commit 3b30cf3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 15 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
brew install nodejs
apt-get install nodejs

How to run:
init.sh
nodejs blah.js


To stop tor instances:
stop.sh


Put testing code in test.js or something like that.
2 changes: 1 addition & 1 deletion countrycodes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
["ar","TN"],
["ar","AE"],
["ar","YE"],
["hy","AM"] ,
["hy","AM"],
["eu","ES"],
["be","BY"],
["bg","BG"],
Expand Down
41 changes: 41 additions & 0 deletions grapevine.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,47 @@ var grapevine = {
console.error('Error: ' + e);
});
},
check_ip_for_country: function(country_code, callback)
{
// Liam plz help


// should derive torPort from country_code
var torPort = 9050;
var socksConfig = {
proxyHost: '127.0.0.1',
proxyPort: torPort,
auths: [ socks.auth.None() ]
};

var httpOptions = {
// this is ip of "whatsmyip" server
host: '104.197.87.137',
port: 80,
path: '/',
method: 'GET',
agent: new socks.HttpAgent(socksConfig)
};

var req = http.request(httpOptions, function(res) {
res.resume();
var response_string = '';
res.on('data', function(d) {
response_string += d;
});
res.on('end', function() {
callback(JSON.parse(response_string));
});
res.on('error', function(err) {
console.log('Error: ' + err);
});
});
req.end();

req.on('error', function(e) {
console.error('Error: ' + e);
});
},
simulate_country: function(search_query, country_code, callback)
{
var that = this;
Expand Down
15 changes: 1 addition & 14 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@

var grapevine = require('./grapevine');

var search_query = 'monkeys';
var from_language = 'en';
var to_language = 'fr';

//grapevine.translate(search_query, from_language, to_language);
//grapevine.get_news_about(search_query, 'en');
grapevine.simulate_country('gorilla attacks', '', function(result){
grapevine.check_ip_for_country('us', function(result){
console.log(result);
});
/*
grapevine.get_json_from_api(
'www.ajax.googleapis.com',
'/ajax/services/search/news?v=1.0',
grapevine.get_socket_for_country(),
function(result){
console.log(result);
});
*/

0 comments on commit 3b30cf3

Please sign in to comment.