Skip to content

Instantly share code, notes, and snippets.

@rrika
Created September 5, 2023 20:54
Show Gist options
  • Save rrika/18aa8b5e94e803c36a1d544a6ed5e8ab to your computer and use it in GitHub Desktop.
Save rrika/18aa8b5e94e803c36a1d544a6ed5e8ab to your computer and use it in GitHub Desktop.
ME: please show me the tweets in the order that they were liked COMPUTER: thats too hard. heres some tweets i think are good.
class Node:
capacity = 10
def __init__(self, index, count):
self.index = index
self.count = count
self.children = []
def __iter__(self):
return iter(self.children)
def __len__(self):
return len(self.children)
def append(self, x):
self.children.append(x)
def build_tree(n):
queue = []
for i in range(0, n, 25):
ntweets = min(n-i, 25)
child = Node(i, ntweets)
if queue:
parent = queue[0]
parent.append(child)
if len(parent) == parent.capacity:
queue.pop(0)
else:
root = child
root.capacity = 9 # whyever
queue.append(child)
return root
def unscramble(likes):
n = len(likes)
t = build_tree(n)
unscrambled = [None] * n
i = 0
def visit(node):
nonlocal i
for j in range(node.count):
unscrambled[node.index + j] = likes[i]
i += 1
for child in node:
visit(child)
visit(t)
return unscrambled
import json
with open("path_to_archive/data/like.js") as f:
likes = json.loads(f.read()[len("window.YTD.like.part0 = "):])
likes = [like["like"] for like in likes]
likes = unscramble(likes)
for like in likes:
print(like["tweetId"], like.get("fullText", "").replace("\n", ""))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment