Compare commits
10 Commits
bdc587901b
...
b82790933b
| Author | SHA1 | Date | |
|---|---|---|---|
| b82790933b | |||
|
|
e3e7ad4c7d | ||
|
|
f840a456af | ||
| d3b62c1c61 | |||
| 352954e79e | |||
|
|
deb1bcf70b | ||
| b9e02380f2 | |||
|
|
b6c0aab42e | ||
| 88d00e2a63 | |||
| 5c4155bb5c |
BIN
Cluccer.pptx
Normal file
BIN
Cluccer.pptx
Normal file
Binary file not shown.
63
dashboard.py
63
dashboard.py
@@ -41,51 +41,26 @@ def words(message):
|
||||
@event('tweet')
|
||||
def generate_tweet(ctx, e):
|
||||
tweet = dict(e.data)
|
||||
# array of indexes that we want to pop from our tweets; this is to save memory
|
||||
pops = [
|
||||
"display_text_range",
|
||||
"in_reply_to_status_id",
|
||||
"in_reply_to_status_id_str",
|
||||
"in_reply_to_user_id",
|
||||
"in_reply_to_user_id_str",
|
||||
"in_reply_to_screen_name",
|
||||
"geo",
|
||||
"coordinates",
|
||||
"place",
|
||||
"contributors",
|
||||
"is_quote_status"
|
||||
]
|
||||
try:
|
||||
try:
|
||||
tweet.pop("display_text_range")
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
tweet.pop("in_reply_to_status_id")
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
tweet.pop("in_reply_to_status_id_str")
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
tweet.pop("in_reply_to_user_id")
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
tweet.pop("in_reply_to_user_id_str")
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
tweet.pop("in_reply_to_screen_name")
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
tweet.pop("geo")
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
tweet.pop("coordinates")
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
tweet.pop("place")
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
tweet.pop("contributors")
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
tweet.pop("is_quote_status")
|
||||
except KeyError:
|
||||
pass
|
||||
for x in pops:
|
||||
try:
|
||||
tweet.pop(x)
|
||||
except KeyError:
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
# base sample on previous one
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
<link rel="icon" type="image/x-icon" href="./media/logo.png">
|
||||
</head>
|
||||
<body>
|
||||
<!-- <div id="tweet" style="height: 200px;"></div> -->
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<div class="logo">
|
||||
@@ -140,25 +139,10 @@
|
||||
memory: 100
|
||||
});
|
||||
block('#pie').piechart();
|
||||
events.connect('pie', '#pie');
|
||||
|
||||
events.connect("tweet", "#latest");
|
||||
events.connect('pie', '#pie');
|
||||
|
||||
// // create a rolling chart block
|
||||
// block('#graph').rolling_chart({
|
||||
// memory: 150,
|
||||
// chart: {
|
||||
// yaxis: {
|
||||
// min: -100,
|
||||
// max: 100
|
||||
// },
|
||||
// xaxis: {
|
||||
// show: false
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
// // connect sample event to graph
|
||||
// events.connect('tweet', '#graph');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -9,6 +9,8 @@ let filters = {
|
||||
sports: []
|
||||
}
|
||||
|
||||
// smartly removes one of the feeds when the window is too narrow for both feeds to be shown properly
|
||||
// it will swap between the "recent" and "filtered" feeds depending on if a filter is active
|
||||
function showFeeds() {
|
||||
if ($(window).width() < 1280) {
|
||||
if(filters.sports.length === 0 && filters.blockedWords.length === 0 && filters.searchedWords.length === 0 && (filters.sorted == "time" && filters.order == "desc")) {
|
||||
@@ -24,8 +26,16 @@ function showFeeds() {
|
||||
}
|
||||
}
|
||||
|
||||
// outputs HTML of a tweet based on the tweet that gets given as input
|
||||
function tweetCell(tweet) {
|
||||
const date = new Date(tweet.created_at);
|
||||
let minutes = date.getMinutes();
|
||||
|
||||
if (minutes < 10) {
|
||||
minutes = "0" + minutes
|
||||
}
|
||||
|
||||
|
||||
var cell = document.createElement("div");
|
||||
cell.innerHTML =
|
||||
`<div class="tweet">
|
||||
@@ -36,9 +46,9 @@ function tweetCell(tweet) {
|
||||
<a class="tweet-nickname" href = "https://www.twitter.com/${tweet.user.screen_name}" target = "_blank">${tweet.user.name}</a>
|
||||
<a class="tweet-username" href = "https://www.twitter.com/${tweet.user.screen_name}" target = "_blank">@${tweet.user.screen_name}</a>
|
||||
</div>
|
||||
<span class="tweet-date"><em>${date.getHours()}:${date.getMinutes()}</em></span>
|
||||
<span class="tweet-date"><em>${date.getHours()}:${minutes}</em></span>
|
||||
</div>
|
||||
<a class="tweet-text" href = "https://www.twitter.com/${tweet.user.screen_name}/status/${tweet.id_str}" target = "_blank">${tweet.text}</a>
|
||||
<a class="tweet-text" href = "https://www.twitter.com/${tweet.user.screen_name}/status/${tweet.id_str}" target = "_blank">${tweet.text}</a>
|
||||
<div class="tweet-interactions">
|
||||
<div class="tweet-interaction tweet-likes">
|
||||
<span class="material-symbols-outlined">favorite</span>
|
||||
@@ -58,12 +68,15 @@ function tweetCell(tweet) {
|
||||
return cell
|
||||
}
|
||||
|
||||
// applies all filters to a list of tweets
|
||||
function filterTweets(tweets, bannedWords=[], searchWords=[], sorted, order) {
|
||||
if(bannedWords.length == 1 && bannedWords[0] == ""){
|
||||
bannedWords = []
|
||||
filters.blockedWords = []
|
||||
}
|
||||
if(searchWords.length == 1 && searchWords[0] == ""){
|
||||
searchWords = []
|
||||
filters.searchedWords = []
|
||||
}
|
||||
if(bannedWords.length > 0){
|
||||
tweets = filterBannedWords(bannedWords, tweets)
|
||||
@@ -74,6 +87,7 @@ function filterTweets(tweets, bannedWords=[], searchWords=[], sorted, order) {
|
||||
return tweets
|
||||
}
|
||||
|
||||
// iterates through each tweet in the list and removes any tweets that contain any of the given words in their text
|
||||
function filterBannedWords(bannedWords, tweets){
|
||||
for (let i = 0; i < tweets.length; i++) {
|
||||
var tweet = tweets[i]
|
||||
@@ -87,6 +101,7 @@ function filterBannedWords(bannedWords, tweets){
|
||||
return tweets
|
||||
}
|
||||
|
||||
// iterates through each tweet in the list and removes any tweets that do not contain any of the given words in their text
|
||||
function searchForWords(searchWords, tweets){
|
||||
var filteredTweets = []
|
||||
for (let i = 0; i < tweets.length; i++) {
|
||||
@@ -103,6 +118,7 @@ function searchForWords(searchWords, tweets){
|
||||
return filteredTweets.reverse()
|
||||
}
|
||||
|
||||
// sorts through a list of tweets based on an array with options (sort)
|
||||
function sortTweets(tweets, sort){
|
||||
if(typeof sort.sortby == 'undefined'){
|
||||
return tweets
|
||||
@@ -134,7 +150,7 @@ function sortTweets(tweets, sort){
|
||||
}
|
||||
if (sort.sortby == "time"){
|
||||
if(sort.order == 'asc'){
|
||||
tweets.sort(function(a,b){return Date(b.created_at)-Date(a.reply_count)})
|
||||
tweets.reverse()
|
||||
} else{
|
||||
tweets.sort(function(a,b){return Date(a.created_at)-Date(b.reply_count)})
|
||||
}
|
||||
|
||||
@@ -31,16 +31,19 @@ $(".sport").on("click", function() {
|
||||
$(this).trigger("selected", [selectedSports.includes(sportName), selectedSports]) // Trigger event
|
||||
})
|
||||
|
||||
//evaluate and alter our page layout when page gets resized
|
||||
$(window).on("resize", function(){
|
||||
showFeeds()
|
||||
});
|
||||
|
||||
//evaluate and alter our page layout when page gets loaded
|
||||
$(window).on("load", function() {
|
||||
showFeeds()
|
||||
})
|
||||
|
||||
let root = document.querySelector(":root")
|
||||
|
||||
//switch between light and dark mode
|
||||
$(".logo").on("click", function() {
|
||||
if (root.style.getPropertyValue("--main-bg") === 'snow') {
|
||||
var audio = new Audio("../media/Chicken.mp3");
|
||||
@@ -63,6 +66,7 @@ $(".logo").on("click", function() {
|
||||
}
|
||||
})
|
||||
|
||||
//when a filter event happens, filter and sort tweets, then remove all old HTML and fill with new HTML
|
||||
$(window).on("filter", function() {
|
||||
var parent = document.querySelector("#filtered")
|
||||
var lastTweet = parent.firstChild
|
||||
@@ -72,6 +76,10 @@ $(window).on("filter", function() {
|
||||
tweets = filterTweets(tweets, filters.blockedWords, filters.searchedWords.concat(filters.sports), filters.sorted, filters.order);
|
||||
tweets = sortTweets(tweets, {"sortby":filters.sorted, "order":filters.order});
|
||||
var displayTweets = tweets.reverse().slice(0, 100).reverse();
|
||||
if(displayTweets.length == 0) {
|
||||
parent.replaceChildren();
|
||||
return
|
||||
}
|
||||
if(!paused) {
|
||||
if(tweetCell(displayTweets[0]) != lastTweet){
|
||||
parent.replaceChildren();
|
||||
@@ -83,6 +91,7 @@ $(window).on("filter", function() {
|
||||
}
|
||||
})
|
||||
|
||||
// toggle html for the sorting dropdown menu
|
||||
$(".current-sort").on("click", function() {
|
||||
$(".sort-dropdown-list li:not(:first-of-type)").toggle()
|
||||
})
|
||||
@@ -96,7 +105,7 @@ $(".sort-dropdown-list li:not(:first-of-type)").on("click", function() {
|
||||
$(".current-sort").html($(this).html())
|
||||
})
|
||||
|
||||
|
||||
// toggle ordering between ascending or descending and changing arrow to match
|
||||
$(".order-btn").on("click", function() {
|
||||
if($(this).html() == "arrow_downward") { // Descending to ascending
|
||||
$(this).html("arrow_upward")
|
||||
@@ -109,6 +118,7 @@ $(".order-btn").on("click", function() {
|
||||
showFeeds()
|
||||
})
|
||||
|
||||
//functions that get called in HTML onchange attributes to trigger filters
|
||||
function updateSearched(searched){
|
||||
searched = searched.split(",");
|
||||
filters.searchedWords = searched;
|
||||
@@ -130,6 +140,7 @@ function updateSort(sort){
|
||||
showFeeds()
|
||||
}
|
||||
|
||||
// toggle between paused and unpaused
|
||||
$(".pause-btn").on("click", function() {
|
||||
if($(".pause-btn").html() == "pause") { // Unpaused to paused
|
||||
$(".pause-btn").html("play_arrow")
|
||||
|
||||
@@ -87,11 +87,11 @@ block.fn.tweets = function(config) {
|
||||
}
|
||||
window.sessionStorage.setItem('tweets', JSON.stringify(tweets));
|
||||
if(!paused) {
|
||||
// remove tweets
|
||||
$list.replaceChildren();
|
||||
var displayTweets = tweets.reverse().slice(0, options.memory).reverse();
|
||||
for (i = 0; i < Math.min(options.memory-1, displayTweets.length); i++){
|
||||
$list.prepend(tweetCell(displayTweets[i]));
|
||||
// remove tweets
|
||||
$list.replaceChildren();
|
||||
var displayTweets = tweets.reverse().slice(0, options.memory).reverse();
|
||||
for (i = 0; i < Math.min(options.memory-1, displayTweets.length); i++){
|
||||
$list.prepend(tweetCell(displayTweets[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -150,13 +150,13 @@ body {
|
||||
}
|
||||
|
||||
.tweet-nickname:hover {
|
||||
color: white;
|
||||
color: var(--main-light);
|
||||
text-decoration: underline;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.tweet-text {
|
||||
color: white;
|
||||
color: var(--main-light);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user