Skip to content

Instantly share code, notes, and snippets.

@hoitomt
Last active December 30, 2015 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hoitomt/7809178 to your computer and use it in GitHub Desktop.
Save hoitomt/7809178 to your computer and use it in GitHub Desktop.
A ruby script runner combined with a phantomjs script that will pull attributes from a specified network request and compare the attributes. Specifically used for auto-tagging

Overview - Autotag Comparer

Status

Work In Progress

Usage

Put the ruby file (url_runner.rb) and the phantom file (resource_sniffer.js) into the same directory. Run the ruby file for fun and profit:

ruby url_runner.rb

Next Steps

Add in the code to compare the response from the local url and the qa url to verify that the request parameters match between the two requests

Authors

Mike Hoitomt, Andres Cubillos

var page = require('webpage').create(),
system = require('system');
var wtdRequest = new RegExp("wtd.gif", "i");
var url = system.args[1];
function parseUrl(url) {
var queryString = url.split('?')[1];
var queryParams = queryString.split('&');
var queryObj = {};
for(i in queryParams) {
var paramArray = queryParams[i].split('=');
var key = paramArray[0];
var value = paramArray[1];
queryObj[key] = value;
}
return queryObj;
}
page.onResourceRequested = function(request){
if(wtdRequest.test(request.url)) {
queryParams = parseUrl(request.url);
console.log(JSON.stringify(queryParams) );
}
};
page.open(url, function(){
phantom.exit();
});
localUrl = 'http://local.apartmentguide.com/';
qaUrl = 'http://www.qa.apartmentguide.com/';
paths = [
'',
'about/',
'hd-info/'
]
paths.each do |path|
local_url = "#{localUrl}#{path}"
qa_url = "#{qaUrl}#{path}"
p "RUNNING #{local_url}"
system "phantomjs resource_sniffer.js #{local_url}"
p "RUNNING #{qa_url}"
system "phantomjs resource_sniffer.js #{qa_url}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment