Skip to content

Commit

Permalink
Merge pull request #19 from legoscia/master
Browse files Browse the repository at this point in the history
Fix for layout change; add rating date
  • Loading branch information
dutts committed Apr 17, 2016
2 parents de58132 + de740ea commit 7238014
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion firefox/addon/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ self.port.on("restaurantScore", function(restaurantScore) {
else {
resultText.textContent = "Hygiene Score : " + restaurantScore.rating + "/5";
}
resultText.appendChild(document.createElement('br'));
resultText.appendChild(document.createTextNode("Rated on " + restaurantScore.date.substring(0, 10)));
}
restaurantScorePlaceholder.appendChild(resultText);

Expand All @@ -152,7 +154,7 @@ var restaurantId = 0;

Array.prototype.forEach.call(restaurantEntries, function (el, i) {

var name = el.querySelector('h2.name a').textContent.trim();
var name = el.querySelector('h2.name').textContent.trim();
var address = el.querySelector('p.address').childNodes[0].textContent.trim();

self.port.emit("queryRestaurant", {id:restaurantId, name:name, address:address});
Expand Down
16 changes: 14 additions & 2 deletions firefox/addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,19 @@ function startListening(worker) {
worker.port.on("queryRestaurant", function(restaurant) {
//console.log(restaurant);

var url = "http://api.ratings.food.gov.uk/Establishments?name=" + encodeURIComponent(restaurant.name) + "&address=" + encodeURIComponent(restaurant.address);
var postcodeRegexp = /[A-Z]{1,2}[0-9]{1,2}[A-Z]{0,1} [0-9][A-Z]{2}/;
var postcodeIndex = restaurant.address.search(postcodeRegexp);
var address;
if (postcodeIndex === -1) {
// this should never happen
address = restaurant.address;
}
else {
address = restaurant.address.substring(postcodeIndex);
}
var url = "http://api.ratings.food.gov.uk/Establishments?name=" + encodeURIComponent(restaurant.name) + "&address=" + encodeURIComponent(address);
var rating = 0;
var ratingDate = '';

var Request = require("sdk/request").Request;
var foodLookupRequest = Request({
Expand All @@ -25,12 +36,13 @@ function startListening(worker) {
if (response.json != null) {
if (response.json.establishments.length > 0) {
rating = response.json.establishments[0].RatingValue;
ratingDate = response.json.establishments[0].RatingDate;
}
else {
rating = -1;
}
}
worker.port.emit("restaurantScore", {id:restaurant.id, rating:rating});
worker.port.emit("restaurantScore", {id:restaurant.id, rating:rating, date:ratingDate});
}
}).get();
});
Expand Down

0 comments on commit 7238014

Please sign in to comment.