Last active
July 5, 2024 18:12
-
-
Save willowiscool/315472e28bfaf814815c83e895f8d0ca to your computer and use it in GitHub Desktop.
download ur twitter data then copy tweets.js to tweets.json and remove the bit before the {
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const USERNAME = "holyshitlois" | |
const COUNT_SELFQT_AS_QT = false | |
const DATE_CHANGES_AT_HR = 5 // 5 am | |
const tweets = require("./tweets.json") | |
/* | |
let replies = tweets.filter(tweet => | |
tweet.tweet.full_text.startsWith("@")) | |
let retweets = tweets.filter(tweet => | |
tweet.tweet.full_text.startsWith("RT")) | |
let quotes = tweets.filter(tweet => | |
tweet.tweet.entities.urls.length > 0 && | |
!tweet.tweet.full_text.startsWith("RT") && | |
tweet.tweet.entities.urls.some(url => | |
url.expanded_url.includes("twitter.com") && | |
(COUNT_SELFQT_AS_QT || !url.expanded_url.includes(USERNAME))))*/ | |
const dateTweets = {}; | |
tweets.forEach(tweet => { | |
// get tweet date | |
const date = new Date(tweet.tweet.created_at) | |
// decrement by 1 day if before date change (i.e. 5am) | |
if (date.getHours() < DATE_CHANGES_AT_HR) { | |
date.setTime(date.getTime() - 24*60*60*1000) | |
} | |
const timestamp = `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()}` | |
if (dateTweets[timestamp] === undefined) { | |
dateTweets[timestamp] = { | |
quotes: 0, | |
retweets: 0, | |
replies: 0, | |
others: 0, | |
} | |
} | |
dateTweets[timestamp][classify(tweet)]++ | |
}) | |
// print dateTweets | |
console.log("date,tweets (excl.),quotes,replies,retweets") | |
Object.entries(dateTweets).forEach(dt => { | |
console.log(`${dt[0]},${dt[1].others},${dt[1].quotes},${dt[1].replies},${dt[1].retweets}`); | |
}) | |
function classify(tweet) { | |
if (tweet.tweet.full_text.startsWith("@")) return "replies" | |
if (tweet.tweet.full_text.startsWith("RT")) return "retweets" | |
if (tweet.tweet.entities.urls.length > 0 && | |
!tweet.tweet.full_text.startsWith("RT") && | |
tweet.tweet.entities.urls.some(url => | |
url.expanded_url.includes("twitter.com") && | |
(COUNT_SELFQT_AS_QT || !url.expanded_url.includes(USERNAME)))) return "quotes" | |
return "others" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment