after class commit
This commit is contained in:
parent
01c46ba645
commit
eb7ad3687c
@ -9,6 +9,16 @@
|
|||||||
#inputs {
|
#inputs {
|
||||||
width: 30em;
|
width: 30em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.book {
|
||||||
|
padding: 10px;
|
||||||
|
border-bottom: 1px solid red;
|
||||||
|
}
|
||||||
|
|
||||||
|
#books {
|
||||||
|
width: 30em;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
<!-- SCRIPTS -->
|
<!-- SCRIPTS -->
|
||||||
<!-- import handlebars -->
|
<!-- import handlebars -->
|
||||||
@ -26,14 +36,20 @@
|
|||||||
<input id="nbr_books" type="number" value="2" min="1" max="5">
|
<input id="nbr_books" type="number" value="2" min="1" max="5">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!--
|
|
||||||
<div id="books">
|
<div id="books">
|
||||||
<script id="books-template" type="text/x-handlebars-template">
|
<script id="books-template" type="text/x-handlebars-template">
|
||||||
{{#each this}}
|
{{#each this}}
|
||||||
|
<div class="book">
|
||||||
|
<div class="title">Title: {{title}}</div>
|
||||||
|
<div class="author">Author: {{author}}</div>
|
||||||
|
<div class="price">Price: {{price}}</div>
|
||||||
|
<div class="kind">Kind: {{kind}}</div>
|
||||||
|
</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
-->
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -51,11 +67,21 @@
|
|||||||
|
|
||||||
// when receiving a custom message form the server
|
// when receiving a custom message form the server
|
||||||
socket.on('all the books we have', function(msg) {
|
socket.on('all the books we have', function(msg) {
|
||||||
console.log('all the books: ' + msg);
|
|
||||||
|
console.log('all the books: ' + JSON.stringify(msg));
|
||||||
|
|
||||||
|
compile_results_and_display(msg);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
function get_books() {
|
||||||
function compile_results_and_dispay(results) {
|
|
||||||
|
socket.emit('give some books', "nothing");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function compile_results_and_display(results) {
|
||||||
|
|
||||||
var template_script = $("#books-template").html();
|
var template_script = $("#books-template").html();
|
||||||
|
|
||||||
@ -66,7 +92,7 @@
|
|||||||
$('#books').append(template(results));
|
$('#books').append(template(results));
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@ -83,7 +83,9 @@
|
|||||||
|
|
||||||
// when receiving a custom message form the server ('search_twitter_results')
|
// when receiving a custom message form the server ('search_twitter_results')
|
||||||
socket.on('search_twitter_results', function(msg) {
|
socket.on('search_twitter_results', function(msg) {
|
||||||
console.log('search_twitter_results: ' + msg);
|
|
||||||
|
console.log('search_twitter_results: ' + JSON.stringify(msg));
|
||||||
|
|
||||||
compile_results_and_dispay(msg);
|
compile_results_and_dispay(msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -93,8 +95,6 @@
|
|||||||
var keyword = document.getElementById("text_field").value;
|
var keyword = document.getElementById("text_field").value;
|
||||||
var hits = document.getElementById("nbr_results").value;
|
var hits = document.getElementById("nbr_results").value;
|
||||||
|
|
||||||
console.log(hits);
|
|
||||||
|
|
||||||
// radio buttons -- filter
|
// radio buttons -- filter
|
||||||
var filter = null;
|
var filter = null;
|
||||||
if(document.getElementById("radio_images").checked) {
|
if(document.getElementById("radio_images").checked) {
|
||||||
|
|||||||
@ -28,33 +28,46 @@ var config = JSON.parse(fs.readFileSync(config_file, "utf8"));
|
|||||||
// create the twitter client
|
// create the twitter client
|
||||||
var client = new twitter(config);
|
var client = new twitter(config);
|
||||||
|
|
||||||
function search_twitter(keyword_value, nbr_hits, filter_value, callback) {
|
function search_twitter(keyword_value, nbr_hits, filter_value) {
|
||||||
|
|
||||||
var search_params = {q: keyword_value, count: nbr_hits};
|
|
||||||
|
//https://dev.twitter.com/rest/reference/get/search/tweets
|
||||||
|
var twitter_search_params = {q: keyword_value, count: nbr_hits};
|
||||||
|
|
||||||
// if there is a filter
|
// if there is a filter
|
||||||
if(filter_value) {
|
if(filter_value) {
|
||||||
search_params.filter = filter_value;
|
twitter_search_params.filter = filter_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
client.get('search/tweets', search_params, function(error, tweets, response) {
|
client.get('search/tweets', twitter_search_params, function(error, tweets, response) {
|
||||||
|
|
||||||
var results = [];
|
var results = [];
|
||||||
|
|
||||||
|
console.log(tweets);
|
||||||
|
|
||||||
if(!error) {
|
if(!error) {
|
||||||
//console.log("got " + tweets.statuses.length + " hits")
|
//console.log("got " + tweets.statuses.length + " hits")
|
||||||
for(tweet of tweets.statuses) {
|
for(tweet of tweets.statuses) {
|
||||||
// console.log(tweet);
|
// console.log(tweet);
|
||||||
let r = {};
|
|
||||||
|
var r = {};
|
||||||
r.text = tweet.text;
|
r.text = tweet.text;
|
||||||
|
|
||||||
if(tweet.entities.media) {
|
if(tweet.entities.media) {
|
||||||
|
|
||||||
r.images = [];
|
r.images = [];
|
||||||
|
|
||||||
for(media of tweet.entities.media) {
|
for(media of tweet.entities.media) {
|
||||||
|
|
||||||
if(media.type == 'photo')
|
if(media.type == 'photo')
|
||||||
|
|
||||||
r.images.push(media.media_url);
|
r.images.push(media.media_url);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
results.push(r);
|
results.push(r);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -62,9 +75,10 @@ function search_twitter(keyword_value, nbr_hits, filter_value, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send results to client
|
// send results to client
|
||||||
//io.emit('search_twitter_results', results);
|
io.emit('search_twitter_results', results);
|
||||||
|
|
||||||
|
//callback(results);
|
||||||
|
|
||||||
callback(results);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -90,13 +104,7 @@ io.on('connection', function(socket) {
|
|||||||
|
|
||||||
console.log('searching twitter with: ' + msg.toString());
|
console.log('searching twitter with: ' + msg.toString());
|
||||||
|
|
||||||
search_twitter(msg.keyword_value, msg.nbr_hits, msg.filter_value, function (results) {
|
search_twitter(msg.keyword_value, msg.nbr_hits, msg.filter_value);
|
||||||
|
|
||||||
console.log(JSON.stringify(results, null, '\t'));
|
|
||||||
|
|
||||||
io.emit('search_twitter_results', results);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user