From 1932afe5f841fd9edfd1d144d677a9edd842af30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Hn=C3=A1t?= Date: Thu, 3 Nov 2022 14:17:50 +0100 Subject: [PATCH] Working live tweets and filtering tweets --- __pycache__/dashboard.cpython-310.pyc | Bin 1576 -> 1576 bytes dashboard_static/js/code.js | 3 ++- dashboard_static/js/events.js | 17 ++++++++++++++--- dashboard_static/lib/tweets.js | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/__pycache__/dashboard.cpython-310.pyc b/__pycache__/dashboard.cpython-310.pyc index ef5ec2f0cc6e928b529135e87c698e9eebc9de8a..4ea8c4538fc05aaad43c3589dd454dfd21a55546 100644 GIT binary patch delta 20 acmZ3%vx0{^pO=@50SK0ENZ!aT%LV{3a|E6M delta 20 acmZ3%vx0{^pO=@50SL5aC2i!EWdi^$jRXt; diff --git a/dashboard_static/js/code.js b/dashboard_static/js/code.js index 680796a..53e2b0c 100644 --- a/dashboard_static/js/code.js +++ b/dashboard_static/js/code.js @@ -32,6 +32,8 @@ function tweetCell(tweet) {
${tweet.user.name} @${tweet.user.screen_name} + +

${tweet.created_at}

${tweet.text}
@@ -54,7 +56,6 @@ function tweetCell(tweet) { } function filterTweets(tweets, bannedWords=[], searchWords=[], sorted, order) { - console.log(searchWords) if(bannedWords.length > 0){ tweets = filterBannedWords(bannedWords, tweets) } diff --git a/dashboard_static/js/events.js b/dashboard_static/js/events.js index 9000e11..7ed73fd 100644 --- a/dashboard_static/js/events.js +++ b/dashboard_static/js/events.js @@ -8,6 +8,10 @@ $(".sport").on("selected", function(e, selected, sports) { window.addEventListener('DOMContentLoaded', (event) => { window.sessionStorage.setItem('tweets', JSON.stringify([])); + // run code every 5 seconds + setInterval(function() { + $(window).trigger("filter"); + }, 1000); }); $(".sport").on("click", function() { @@ -66,19 +70,26 @@ $(".logo").on("click", function() { }) $(window).on("filter", function() { + console.log("called") var parent = document.querySelector("#filtered") parent.replaceChildren(); - console.debug(filters); + console.log(filters); tweets = window.sessionStorage.getItem('tweets'); tweets = JSON.parse(tweets); + console.log(tweets.length) tweets = filterTweets(tweets, filters.blockedWords, filters.searchedWords.concat(filters.sports), filters.sorted, filters.order); tweets = sortTweets(tweets); - for (i = 0; i < Math.min(tweets.length, 20); i++){ - parent.append(tweetCell(tweets[i])); + var displayTweets = tweets.reverse().slice(0, 20).reverse(); + for (i = 0; i < 19; i++){ + console.log("FDS") + parent.prepend(tweetCell(displayTweets[i])); + console.log("FDS 2") } }) + + $(".order-btn").on("click", function() { if($(this).html() == "arrow_downward") { // Descending to ascending $(this).html("arrow_upward") diff --git a/dashboard_static/lib/tweets.js b/dashboard_static/lib/tweets.js index 2e99678..da10619 100644 --- a/dashboard_static/lib/tweets.js +++ b/dashboard_static/lib/tweets.js @@ -74,10 +74,10 @@ block.fn.tweets = function(config) { // store list for later // var $list = $("div.tweetcontainer"); var $list = document.querySelector("#latest") + window.sessionStorage.setItem('tweets', JSON.stringify([])); // register default handler for handling tweet data this.actions(function(e, tweet){ - $(window).trigger("filter"); tweets = window.sessionStorage.getItem('tweets'); tweets = JSON.parse(tweets); tweets.push(tweet);