Skip to content

Instantly share code, notes, and snippets.

@llimllib
Created October 10, 2021 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save llimllib/b96bf6e63246f50ecfc6e70c88455af5 to your computer and use it in GitHub Desktop.
Save llimllib/b96bf6e63246f50ecfc6e70c88455af5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import re
import requests
import sys
import time
if len(sys.argv) < 2:
print("usage: python oldest.py <username>")
sys.exit(1)
res = requests.get(f"https://news.ycombinator.com/threads?id={sys.argv[1]}")
last_cursor = ""
while 1:
cursor = re.findall(r'next=(\d+)"', res.text)
if len(cursor) == 0 or cursor[0] == last_cursor:
print(f"exiting: {cursor} {res}")
break
cursor = cursor[0]
url = f"https://news.ycombinator.com/threads?id={sys.argv[1]}&next={cursor}"
print(url)
res = requests.get(url)
last_cursor = cursor
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment