trying to get nearby detail card working
This commit is contained in:
parent
482de8d703
commit
9ae61c8b1c
17
server.js
17
server.js
@ -110,6 +110,23 @@ app.get('/rightbyme', cache('15 minutes'), (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/nearbydetail', cache('15 minutes'), (req, res) => {
|
||||||
|
if (req.query.hasOwnProperty('id'))
|
||||||
|
rightbyme.doGetMoreDetail(req.query.id)
|
||||||
|
.then((d) => {
|
||||||
|
res.send(d);
|
||||||
|
}).catch((e) => {
|
||||||
|
logger.error(e);
|
||||||
|
res.status(500).send('There was an error!');
|
||||||
|
});
|
||||||
|
|
||||||
|
else {
|
||||||
|
// throw new Error('Weather: LL missing');
|
||||||
|
logger.warn('FS: LL missing');
|
||||||
|
res.status(500).send('LL Missing');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
app.get('/news', cache('15 minutes'), (req, res) => {
|
app.get('/news', cache('15 minutes'), (req, res) => {
|
||||||
euronews.getEuroNews().then((d) => {
|
euronews.getEuroNews().then((d) => {
|
||||||
res.send(d);
|
res.send(d);
|
||||||
|
@ -5,7 +5,7 @@ const yelp = require('yelp-fusion');
|
|||||||
|
|
||||||
const client = yelp.client('YlF_b6D149xr_xnrrYudlSnpn1A53b67vALlIK2HnD0ymBXQocRvPW3KjGN8jZNw0KnyAqxGaOzU7CLVPr84_KbnTxutNRXFVR9axmRqGN6ccda1xahoZo58KC2GWnYx');
|
const client = yelp.client('YlF_b6D149xr_xnrrYudlSnpn1A53b67vALlIK2HnD0ymBXQocRvPW3KjGN8jZNw0KnyAqxGaOzU7CLVPr84_KbnTxutNRXFVR9axmRqGN6ccda1xahoZo58KC2GWnYx');
|
||||||
|
|
||||||
const { get, isEmpty } = require('lodash');
|
const { get, isEmpty, has } = require('lodash');
|
||||||
|
|
||||||
const { reduceExplore, reduceYelp, reduceFullFS, reduceTwitter } = require('./reducers/rightbyme');
|
const { reduceExplore, reduceYelp, reduceFullFS, reduceTwitter } = require('./reducers/rightbyme');
|
||||||
|
|
||||||
@ -32,9 +32,9 @@ function doFSVenueSearch(ll, data = {}) {
|
|||||||
|
|
||||||
if (isEmpty(payLoad))
|
if (isEmpty(payLoad))
|
||||||
foursquare.venues.search(fsObj, function(err, fsData) {
|
foursquare.venues.search(fsObj, function(err, fsData) {
|
||||||
if (err)
|
if (err) {
|
||||||
{
|
|
||||||
logger.debug(err);
|
logger.debug(err);
|
||||||
|
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -68,9 +68,9 @@ function doFSVenueExplore(ll) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
foursquare.venues.explore(fsObj, function(err, fsData) {
|
foursquare.venues.explore(fsObj, function(err, fsData) {
|
||||||
if (err)
|
if (err) {
|
||||||
{
|
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -99,11 +99,13 @@ function doYelpSearch(data = {}) {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!isEmpty(payLoad)) {
|
if (!isEmpty(payLoad)) {
|
||||||
yelpSearch.term = payLoad.name;
|
yelpSearch.term = payLoad.name;
|
||||||
|
yelpSearch.location = payLoad.address;
|
||||||
yelpSearch.latitude = payLoad.latitude;
|
yelpSearch.latitude = payLoad.latitude;
|
||||||
yelpSearch.longitude = payLoad.longitude;
|
yelpSearch.longitude = payLoad.longitude;
|
||||||
yelpSearch.location = payLoad.address;
|
|
||||||
yelpSearch.radius = 250;
|
// yelpSearch.radius = 250;
|
||||||
yelpSearch.sort_by = 'best_match';
|
yelpSearch.sort_by = 'distance';
|
||||||
|
logger.debug(yelpSearch);
|
||||||
client.search(yelpSearch).then(response => {
|
client.search(yelpSearch).then(response => {
|
||||||
const respArray = get(response, 'jsonBody.businesses');
|
const respArray = get(response, 'jsonBody.businesses');
|
||||||
yelpReply = (respArray.length > 0) ? respArray[0] : {};
|
yelpReply = (respArray.length > 0) ? respArray[0] : {};
|
||||||
@ -139,8 +141,10 @@ function doFSGetFullVenue(data = {}) {
|
|||||||
if (err)
|
if (err)
|
||||||
return reject(err);
|
return reject(err);
|
||||||
else {
|
else {
|
||||||
|
console.log(JSON.stringify(fsData));
|
||||||
|
const initPayload = (has(payLoad, 'name')) ? {} : reduceExplore(get(fsData, 'response.venue'));
|
||||||
const partPayload = reduceFullFS(get(fsData, 'response.venue'));
|
const partPayload = reduceFullFS(get(fsData, 'response.venue'));
|
||||||
const newPayload = Object.assign(payLoad, partPayload);
|
const newPayload = Object.assign(payLoad, initPayload, partPayload);
|
||||||
|
|
||||||
return resolve(newPayload);
|
return resolve(newPayload);
|
||||||
}
|
}
|
||||||
@ -230,6 +234,42 @@ function doGetRightByMe(ll) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function doGetMoreDetail(id) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
doFSGetFullVenue({ 'id':id })
|
||||||
|
.catch((e) => {
|
||||||
|
logger.error(e);
|
||||||
|
|
||||||
|
return reject(e);
|
||||||
|
// res.status(500).send('There was an error!');
|
||||||
|
})
|
||||||
|
.then((d) => {
|
||||||
|
return doYelpSearch(d);
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
logger.error(e);
|
||||||
|
|
||||||
|
return reject(e);
|
||||||
|
// res.status(500).send('There was an error!');
|
||||||
|
})
|
||||||
|
.then((d) => {
|
||||||
|
// return doYelpSearch(d)
|
||||||
|
return doTweetSearch(d);
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
logger.error(e);
|
||||||
|
|
||||||
|
return reject(e);
|
||||||
|
// res.status(500).send('There was an error!');
|
||||||
|
})
|
||||||
|
.then((d) => {
|
||||||
|
logger.info('Final', d.name, d.id);
|
||||||
|
|
||||||
|
return resolve(d);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function test(ll, near) {
|
async function test(ll, near) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
doFSVenueExplore(ll)
|
doFSVenueExplore(ll)
|
||||||
@ -272,7 +312,7 @@ async function test(ll, near) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
module.exports = { doGetRightByMe };
|
module.exports = { doGetRightByMe, doGetMoreDetail };
|
||||||
|
|
||||||
const tests = {
|
const tests = {
|
||||||
'cruachan' : '56.3946,-5.1166',
|
'cruachan' : '56.3946,-5.1166',
|
||||||
|
@ -7,6 +7,7 @@ const { get, isEmpty } = require('lodash');
|
|||||||
logger.level = 'debug';
|
logger.level = 'debug';
|
||||||
|
|
||||||
function reduceExplore(data) {
|
function reduceExplore(data) {
|
||||||
|
const cleaner = /\((.*?)\)/g;
|
||||||
const obj = {};
|
const obj = {};
|
||||||
if (typeof data === 'undefined' || isEmpty(data)) return obj;
|
if (typeof data === 'undefined' || isEmpty(data)) return obj;
|
||||||
const { categories, location, contact } = data;
|
const { categories, location, contact } = data;
|
||||||
@ -24,7 +25,7 @@ function reduceExplore(data) {
|
|||||||
obj.icon = (iconPrefix !== '') ? `${iconPrefix}64${iconSuffix}` : '';
|
obj.icon = (iconPrefix !== '') ? `${iconPrefix}64${iconSuffix}` : '';
|
||||||
obj.id = get(localObj, 'id', '');
|
obj.id = get(localObj, 'id', '');
|
||||||
obj.provider = 'foursquare';
|
obj.provider = 'foursquare';
|
||||||
obj.address = get(location, 'formattedAddress', []).join(', ');
|
obj.address = get(location, 'formattedAddress', []).join(', ').replace(cleaner, '');
|
||||||
obj.city = get(location, 'city', '');
|
obj.city = get(location, 'city', '');
|
||||||
obj.state = get(location, 'state', '');
|
obj.state = get(location, 'state', '');
|
||||||
obj.postcode = get(location, 'postalCode', '');
|
obj.postcode = get(location, 'postalCode', '');
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
const CACHE_VERSION = { 'version': '0.0.480' };
|
const CACHE_VERSION = { 'version': '0.0.483' };
|
||||||
const dataCacheName = 'jubileeData-v1';
|
const dataCacheName = 'jubileeData-v1';
|
||||||
const cacheName = 'jubilee-final-1';
|
const cacheName = 'jubilee-final-1';
|
||||||
const filesToCache = [
|
const filesToCache = [
|
||||||
|
@ -18,7 +18,7 @@ const newsCollection = new NewsCollection();
|
|||||||
|
|
||||||
const NewsItemView = Backbone.View.extend({
|
const NewsItemView = Backbone.View.extend({
|
||||||
'tagName': 'div',
|
'tagName': 'div',
|
||||||
'className' : 'newsItem',
|
'className' : 'newsItem mui-container',
|
||||||
'template': _.template(`
|
'template': _.template(`
|
||||||
|
|
||||||
<div class="mui--text-subhead mui--text-accent"><%=title%></div>
|
<div class="mui--text-subhead mui--text-accent"><%=title%></div>
|
||||||
|
@ -18,7 +18,7 @@ const { AgendaModel, AgendaView } = require('./Agenda');
|
|||||||
const { TrafficModel, TrafficView } = require('./Traffic');
|
const { TrafficModel, TrafficView } = require('./Traffic');
|
||||||
var app = app || {};
|
var app = app || {};
|
||||||
|
|
||||||
const live = true;
|
const live = false;
|
||||||
|
|
||||||
if (live) {
|
if (live) {
|
||||||
window.loc = 'https://jubilee.silvrtree.co.uk';
|
window.loc = 'https://jubilee.silvrtree.co.uk';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user