Skip to content

Instantly share code, notes, and snippets.

@sk22
Created October 20, 2020 22:57
Show Gist options
  • Save sk22/9fd5ecbcd5a7a02385d61aba7b28c1f0 to your computer and use it in GitHub Desktop.
Save sk22/9fd5ecbcd5a7a02385d61aba7b28c1f0 to your computer and use it in GitHub Desktop.
#!/bin/sh
# run inside twitter-archive/data - there should be a tweet.js file
# this tweet.js file is meant to be read by the browser and can be
# a pain to import into a node.js repl. this script adds the necessary
# lines that let your import the tweets using a simple node require()
echo "const window = { YTD: { tweet: {} } }" > tweets.module.js
cat tweet.js >> tweets.module.js
echo >> tweets.module.js
echo "module.exports = window.YTD.tweet" >> tweets.module.js
// run these commands inside a node repl
/* import tweets */
const tweets = require('./tweets.module.js')
/* best tweets */
console.log(tweets.part0.map(t => t.tweet)
.sort((o1, o2) => Number(o2.favorite_count) - Number(o1.favorite_count))
.slice(0, 10)
.map(t => `https://twitter.com/_/status/${t.id_str}`)
.join('\n'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment