Some fixes for right by me, includes tweets :) chirp chirp

This commit is contained in:
Martin Donnelly 2018-03-01 12:26:19 +00:00
parent efd29fa92a
commit 326ca1005b
10 changed files with 168 additions and 40 deletions

View File

@ -20,12 +20,12 @@ gulp.task('bundleBackbone', function () {
return b.bundle()
.pipe(source('app.js'))
.pipe(buffer())
.pipe(stripDebug())
// .pipe(stripDebug())
.pipe(rename('bundle.js'))
.pipe(sourcemaps.init({ 'loadMaps': true }))
// Add transformation tasks to the pipeline here.
.pipe(uglify())
// .pipe(uglify())
.on('error', gutil.log)
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./live/js'));

14
package-lock.json generated
View File

@ -1966,6 +1966,11 @@
"integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=",
"dev": true
},
"deep-extend": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.5.0.tgz",
"integrity": "sha1-bvSgmwX5iw41jW2T1Mo8rsZnKAM="
},
"deep-is": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz",
@ -11042,6 +11047,15 @@
"integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=",
"optional": true
},
"twitter": {
"version": "1.7.1",
"resolved": "https://registry.npmjs.org/twitter/-/twitter-1.7.1.tgz",
"integrity": "sha1-B2I3jx3BwFDkj2ZqypBOJLGpYvQ=",
"requires": {
"deep-extend": "0.5.0",
"request": "2.83.0"
}
},
"type-check": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz",

View File

@ -34,6 +34,7 @@
"muicss": "^0.9.36",
"node-foursquare-venues": "^1.1.0",
"openweather-apis": "^3.3.5",
"twitter": "^1.7.1",
"uglifyify": "^4.0.5",
"underscore": "^1.8.3",
"yelp-fusion": "^2.0.3"

View File

@ -1,14 +1,20 @@
const logger = require('log4js').getLogger('FSQ');
const foursquare = require('node-foursquare-venues')('IXXFUGW3NC3DEVS2V5EU4NV4CL5E12AYGUPIR2D3U3B5DX4B', 'MZRIJDCEKUMVERA1OKVAIZI0TYAEBD3W2A2AGPTPI5TOLL1D', '20170801');
const Twitter = require('twitter');
const yelp = require('yelp-fusion');
const client = yelp.client('YlF_b6D149xr_xnrrYudlSnpn1A53b67vALlIK2HnD0ymBXQocRvPW3KjGN8jZNw0KnyAqxGaOzU7CLVPr84_KbnTxutNRXFVR9axmRqGN6ccda1xahoZo58KC2GWnYx');
const { get, isEmpty } = require('lodash');
const { reduceExplore, reduceYelp, reduceFullFS } = require('./reducers/rightbyme');
const { reduceExplore, reduceYelp, reduceFullFS, reduceTwitter } = require('./reducers/rightbyme');
const twitterClient = new Twitter({
'consumer_key': 'bJvwgjA9O52j7rC6mqoeefPLO',
'consumer_secret': 'NB6ASJxxMI9yaOgTAlWEpd18J1BdtIOYb4iz1HivIVpPqSLBY5',
'access_token_key': '4773651-1IrcQuKzEBQYe89Ooe0wCEP3reiyJZ1SQl003b5DoU',
'access_token_secret': 'AHWGNQLAVGrXeUU3FU1ubdro4z5zc5igeiN4B9qI99xIt'
});
logger.level = 'debug';
@ -140,6 +146,41 @@ function doFSGetFullVenue(data = {}) {
});
}
function doTweetSearch(data = {}) {
const payLoad = Object.assign({}, data);
logger.debug('>> doTweetSearch');
return new Promise((resolve, reject) => {
if (!isEmpty(payLoad)) {
console.log('payLoad.twitter', payLoad.twitter);
if (payLoad.twitter !== '') {
const params = { 'screen_name': payLoad.twitter };
twitterClient.get('statuses/user_timeline', params, function(error, tweets, response) {
if (error)
return reject(error);
else {
// const partPayload = reduceFullFS(get(fsData, 'response.venue'));
// const newPayload = Object.assign(payLoad, partPayload);
// return resolve(newPayload);
const reducedTweets = reduceTwitter(tweets);
payLoad.tweets = reducedTweets;
return resolve(payLoad);
}
});
}
else
return resolve(payLoad);
}
else
return resolve(payLoad);
});
}
function doGetRightByMe(ll) {
return new Promise((resolve, reject) => {
doFSVenueExplore(ll)
@ -161,6 +202,10 @@ function doGetRightByMe(ll) {
return reject(e);
// res.status(500).send('There was an error!');
})
.then((d) => {
// return doYelpSearch(d)
return doTweetSearch(d);
})
.then((d) => {
// return doYelpSearch(d)
return doFSGetFullVenue(d);
@ -180,31 +225,46 @@ function doGetRightByMe(ll) {
}
async function test(ll, near) {
console.log('TESTING...');
await doFSVenueExplore(ll)
.then((d) => {
return doFSVenueSearch(ll, d);
})
.catch((e) => {
logger.error(e);
// res.status(500).send('There was an error!');
})
.then((d) => {
return doYelpSearch(d);
})
.catch((e) => {
logger.error(e);
// res.status(500).send('There was an error!');
})
.then((d) => {
// return doYelpSearch(d)
return doFSGetFullVenue(d);
})
.then((d) => {
logger.info('Final', d.name, d.id);
})
return new Promise((resolve, reject) => {
doFSVenueExplore(ll)
.then((d) => {
return doFSVenueSearch(ll, d);
})
.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);
})
.then((d) => {
// return doYelpSearch(d)
return doFSGetFullVenue(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);
});
});
}
module.exports = { doGetRightByMe };
@ -226,15 +286,13 @@ const tests = {
// tesco helensburgh
// const location = { 'homeDistance':12.941340256604686, 'workDistance':33.47577415510536, 'latitude':56.003466, 'longitude':-4.733689, 'atHome':false, 'atWork':false, 'timestamp':1519638618383, 'll':'56.003466,-4.733689', 'llFixed':'56.003,-4.734', 'city':'Helensburgh', 'cityCC':'Helensburgh,GB', 'address':'9-13 Sinclair St, Helensburgh G84, UK' };
// test('56.3946,-5.1166');
// test('55.863991,-4.257788');
// howling wolf http://localhost:8110/rightbyme?ll=55.863991,-4.257788
/*
{"response":{"result":[{"cards":[{"card_id":"83a014c3-c0a4-3242-b5a8-79d011b677d6","rendering_engine":"custom","type":"WEATHER","type_display_name":"Weather","ttl":1519810720,"layout":{"template":"weather"},"data":{},"modules":{},"reason":"","notify":false,"ranking_arguments":{"STREAM_TYPE:MAIN":1.0,"rule_score":3.0,"TIER":3.0,"TIME_OF_DAY_RANGE:MORNING":1.0,"score":0.6},"instrumentation":{"rid":"13kfji9d97ld0","bucket":"ga"}},{"card_id":"c81eac4b-4553-3d60-85a6-178968bd5065","rendering_engine":"custom","type":"NEWS_DIGEST","type_display_name":"News Digest","ttl":1519810720,"layout":{"template":"news_digest"},"data":{},"modules":{},"reason":"","notify":false,"ranking_arguments":{"STREAM_TYPE:MAIN":1.0,"rule_score":2.0,"TIER":2.0,"TIME_OF_DAY_RANGE:MORNING":1.0,"score":0.55},"instrumentation":{"rid":"13kfji9d97ld0","bucket":"ga"}},{"card_id":"4b5b8c71-58d2-3f26-abce-318e3d3a01d6","rendering_engine":"custom","type":"MORNING_NIGHT","type_display_name":"Set Alarm","ttl":1519810720,"layout":{"template":"morning_night"},"data":{},"modules":{},"reason":"","notify":false,"ranking_arguments":{"USER_LOCATION:OTHER":1.0,"USER_SPEED:STILL":1.0,"STREAM_TYPE:MAIN":1.0,"rule_score":3.0,"TIER":3.0,"TIME_OF_DAY_RANGE:MORNING":1.0,"score":0.5},"instrumentation":{"rid":"13kfji9d97ld0","bucket":"ga"}},{"card_id":"bcacee7a-d79a-3e4e-a5b8-77c5b6480a8c","rendering_engine":"custom","type":"CALENDAR","type_display_name":"Calendar","ttl":1519810720,"layout":{"template":"calendar"},"data":{},"modules":{},"reason":"","notify":false,"ranking_arguments":{"USER_LOCATION:OTHER":1.0,"STREAM_TYPE:MAIN":1.0,"rule_score":2.0,"TIER":2.0,"TIME_OF_DAY_RANGE:MORNING":1.0,"score":0.25},"instrumentation":{"rid":"13kfji9d97ld0","bucket":"ga"}},{"card_id":"9953c0e9-5b77-3162-bcf4-e19fcd1f541f","rendering_engine":"custom","type":"VENUE_INFO","type_display_name":"Venues","ttl":1519641520,"layout":{"template":"venue_info"},"data":{"name":"Tesco","category":"Grocery Store","iconUrl":"https://ss3.4sqi.net/img/categories_v2/shops/food_grocery_64.png","id":"4c5ff51213791b8d0d5c4eaf","provider":"foursquare","tips":["Prepare to be deafened by relief calls over the loudspeaker"],"images":[],"address":"23-25 Sinclair Street","city":"Helensburgh","state":"Argyll and Bute","zip":"G84 8SR","twitter":{"handle":"uktescooffers","viewIntent":"https://twitter.com/uktescooffers#Intent;action=android.intent.action.VIEW;package=com.twitter.android;end","tweetIntent":"#Intent;action=android.intent.action.SEND;component=com.twitter.android/.PostActivity;S.android.intent.extra.TEXT=@uktescooffers;end"},"yelp":{"url":"https://m.yelp.com/biz/tesco-stores-helensburgh?adjust_creative=ogmBMO91tbdmscbTIaQEdA&utm_campaign=yelp_api&utm_medium=api_v2_search&utm_source=ogmBMO91tbdmscbTIaQEdA","rating":3.5,"reviewCount":4,"viewIntent":"https://m.yelp.com/biz/tesco-stores-helensburgh?adjust_creative=ogmBMO91tbdmscbTIaQEdA&utm_campaign=yelp_api&utm_medium=api_v2_search&utm_source=ogmBMO91tbdmscbTIaQEdA#Intent;action=android.intent.action.VIEW;end"}},"modules":{},"reason":"","notify":false,"ranking_arguments":{"poi_latitude":56.00348039818216,"poi_longitude":-4.733884334564209,"USER_LOCATION:OTHER":1.0,"req_longitude":-4.7336884,"req_latitude":56.003464,"STREAM_TYPE:MAIN":1.0,"USER_LOCATION_POI_CONFIDENCE:HIGH":1.0,"rule_score":0.0,"TIER":0.0,"USER_DIST_FROM_REQ_LOC:WITHIN_100M":1.0,"score":0.25},"instrumentation":{"rid":"13kfji9d97ld0","bucket":"ga"}},{"card_id":"eea4f59a-e8a2-3e12-a917-96e254c416d5","rendering_engine":"custom","type":"VENUE_CHOOSER","type_display_name":"Around Me","ttl":1519641520,"layout":{"template":"venue_chooser"},"data":{"venues":[{"name":"Lido's Fish & Chips","category":"Fish & Chips Shop","iconUrl":"https://ss3.4sqi.net/img/categories_v2/food/fishandchips_64.png","id":"4b9a9a77f964a5207ec535e3","provider":"foursquare","eid":"{\"card\":\"venue\",\"id\":\"4b9a9a77f964a5207ec535e3\"}"},{"name":"Mr Kebab","category":"Fast Food Restaurant","iconUrl":"https://ss3.4sqi.net/img/categories_v2/food/fastfo
{"response":{"result":[{"cards":[{"card_id":"9953c0e9-5b77-3162-bcf4-e19fcd1f541f","rendering_engine":"custom","type":"VENUE_INFO","type_display_name":"Venues","ttl":1519654292,"layout":{"template":"venue_info"},"data":{"name":"Speirs Wharf","category":"Pool","iconUrl":"https://ss3.4sqi.net/img/categories_v2/parks_outdoors/pool_64.png","id":"5211c15a11d2c83298e7f8c2","provider":"foursquare","tips":[],"images":["https://igx.4sqi.net/img/general/640x640/72939115_8s_CraZskGLT5uJz5DzRiyBvKXgy6BobQBH5u0Vcsy4.jpg","https://igx.4sqi.net/img/general/960x364/62519220_Z_xAdlllLg7Mb1BUt1b9G18IKTpF1jyeNqGCMo0WhRs.jpg","https://igx.4sqi.net/img/general/960x541/24390977_Ws2HHTyM1zKBlvejccG1BxGTt0hKBURtWQOPPxYc7IM.jpg","https://igx.4sqi.net/img/general/960x960/149524__j5bRwPX5zy5RmOu-uleVtQ-KekAS-rXAJLgc_JjipY.jpg","https://igx.4sqi.net/img/general/640x640/4894760_ZOelH_F7ljq0Mjk6Zzs7KHH8-Dn470lbq4IfFg7WGiM.jpg","https://igx.4sqi.net/img/general/640x640/4894760_kW7NmETQYJxkGfBBnhHhQdDHcVouBj7OWpZBbyy0OTM.jpg"],"telephone":"","address":"","city":"","state":"","zip":"","latitude":55.872669822119796,"longitude":-4.257480441815151,"twitter":{"handle":null,"viewIntent":null,"tweetIntent":null},"yelp":{"url":null,"rating":0.0,"reviewCount":0,"viewIntent":null}},"modules":{},"reason":"","notify":false,"ranking_arguments":{"poi_latitude":55.872669822119796,"poi_longitude":-4.257480441815151,"USER_LOCATION:OTHER":1.0,"req_longitude":-4.2577868,"req_latitude":55.86399,"USER_LOCATION_POI_CONFIDENCE:HIGH":1.0,"STREAM_TYPE":1.0,"rule_score":0.0,"TIER":0.0,"USER_DIST_FROM_REQ_LOC:WITHIN_100M":1.0,"score":0.0},"instrumentation":{"rid":"fn62krdd981s4","bucket":"ga"}}]}],"error":null}}
*/

View File

@ -82,6 +82,7 @@ function reduceFullFS(data) {
let ratioHeight = ~~(height / ratio);
if (ratioHeight <= 0) ratioHeight = 640;
console.log(`${width}, ${height} => ${640}, ${ratioHeight}`);
return `${prefix}${640}x${ratioHeight}${suffix}`;
});
}
@ -96,4 +97,14 @@ function reduceFullFS(data) {
return obj;
}
module.exports = { reduceExplore, reduceYelp, reduceFullFS };
function reduceTwitter(data) {
let obj = [];
if (data.length > 0)
obj = data.map(item => {
return get(item, 'text');
});
return obj;
}
module.exports = { reduceExplore, reduceYelp, reduceFullFS, reduceTwitter };

View File

@ -17,7 +17,7 @@
border-radius: 3px;
background-color: #f5f5f5;
padding: 5px;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
box-shadow: 0 2px 2px 0 rgba(0,0,0,0.05), 0 2px 1px -2px rgba(0,0,0,0.05), 0 1px 5px 0 rgba(0,0,0,0.05)
}
.scrollCardHalf {

View File

@ -11,7 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
const CACHE_VERSION = 8;
const CACHE_VERSION = 9;
const dataCacheName = 'jubileeData-v1';
const cacheName = 'jubilee-final-1';
const filesToCache = [

View File

@ -117,13 +117,18 @@ const LocationModel = Backbone.Model.extend({
}
else {
newLocation.city = current.city;
const currentTime = new Date().getTime();
const distanceFromLast = distance(current.latitude, current.longitude, latitude, longitude);
const lastGeocode = this.get('lastGeocode');
const distanceFromLastGeocode = distance(lastGeocode.lat, lastGeocode.lng, latitude, longitude);
console.log('>> distance from last record', distanceFromLast);
console.log('>> distanceFromLastGeocode', distanceFromLastGeocode, TimeFormat.fromMs(timestamp - lastGeocode.timestamp, 'hh:mm:ss'));
if ((distanceFromLast > 0.5 && distanceFromLast < 2.0) || (timestamp - current.timestamp > 900000)) {
// console.log('>> distanceFromLastGeocode', distanceFromLastGeocode, TimeFormat.fromMs(timestamp - lastGeocode.timestamp, 'hh:mm:ss'));
console.log('>> distanceFromLastGeocode', distanceFromLastGeocode, TimeFormat.fromMs(currentTime - lastGeocode.timestamp, 'hh:mm:ss'));
console.log(`(currentTime:${currentTime}, timestamp:${timestamp}, lastGeocode.timestamp:${lastGeocode.timestamp})`);
console.log('(currentTime - current.timestamp > 900000) ' , (currentTime - current.timestamp > 900000));
//if ((distanceFromLast > 0.5 && distanceFromLast < 2.0) || (timestamp - current.timestamp > 900000)) {
if ((distanceFromLast > 0.5 && distanceFromLast < 2.0) || (currentTime - current.timestamp > 900000)) {
// dont bother re geocoding
console.log('Slightly moved from previous');
this.set('location', newLocation);
@ -137,9 +142,12 @@ const LocationModel = Backbone.Model.extend({
newLocation.city = res[0].city;
newLocation.cityCC = `${res[0].city},${res[0].countryCode}`;
newLocation.address = res[0].formattedAddress;
console.log('!!! Setting location...');
this.set('location', newLocation);
this.set('lastGeocode', { 'lat':latitude, 'lng':longitude, 'timestamp':timestamp });
this.set('moving', moving);
console.log(this);
}.bind(this))
.catch(function(err) {
console.error(err);

View File

@ -71,7 +71,7 @@ const ByMeView = Backbone.View.extend({
`),
'tipsTemplate': _.template(`
<div id='bymeTips'>
<div class="mui--text-subhead">Tips</div>
<div class="mui--text-body2">Tips</div>
<div class='scrolling-wrapper-flexbox' style="height: 100px;">
<%_.forEach(tips, function(i) {%>
<div class="scrollCardHalf mui--text-body1">
@ -92,6 +92,18 @@ const ByMeView = Backbone.View.extend({
</div>
</div>
`),
'tweetsTemplate': _.template(`
<div id='bymeTweets'>
<div class="mui--text-body2">Tweets</div>
<div class='scrolling-wrapper-flexbox' style="height: 100px;">
<%_.forEach(tweets, function(i) {%>
<div class="scrollCardHalf mui--text-body1">
<%=i %>
</div>
<%}) %>
</div>
</div>
`),
'initialize': function(options) {
this.eventBus = options.eventBus;
this.location = options.location;
@ -141,6 +153,9 @@ const ByMeView = Backbone.View.extend({
if (!isEmpty(m.tips))
contents.push(this.tipsTemplate(m));
if (!isEmpty(m.tweets))
contents.push(this.tweetsTemplate(m));
this.$el.html(contents.join(''));
// console.log(this.el);
this.$el.parent().children('#byMeTitle').html(m.name);

View File

@ -12,19 +12,40 @@ const { ByMeModel, ByMeView } = require('./RightByMe');
var app = app || {};
window.loc = 'https://jubilee.silvrtree.co.uk';
// window.loc = 'http://localhost:8110';
const live = true;
(function () {
if (live) {
window.loc = 'https://jubilee.silvrtree.co.uk';
if ('serviceWorker' in navigator)
navigator.serviceWorker
.register('./service-worker.js')
.then(function() {
console.log('Service Worker Registered');
});
}
else
window.loc = 'http://localhost:8110';
/* var ContainerView = Backbone.View.extend({
'myChildView': null,
'render': function() {
this.$el.html('Greeting Area');
this.$el.append(this.myChildView.$el);
return this;
}
});*/
(function () {
const offline = false;
/* var myRouter = Backbone.Router.extend({
//
});*/
app.eventBus = _.extend({}, Backbone.Events);
app.locationModel = new LocationModel();