Created
October 10, 2021 01:47
-
-
Save llimllib/b96bf6e63246f50ecfc6e70c88455af5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/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