Skip to content

Instantly share code, notes, and snippets.

@belkarx
Last active December 3, 2022 03:54
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 belkarx/33cfdda5b6c52ea45198d0bc427fa990 to your computer and use it in GitHub Desktop.
Save belkarx/33cfdda5b6c52ea45198d0bc427fa990 to your computer and use it in GitHub Desktop.
Correlates LessWrong usernames to Hacker News usernames (25% of active LW users, n=355, are also on Hacker News)
import json
import requests
d = # grab data from here: https://www.lesswrong.com/graphiql?query=%20%20%20%20%7B%0A%20%20%20%20%20%20posts%28input%3A%20%7B%0A%20%20%20%20%20%20%20%20terms%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20view%3A%20%22new%22%0A%20%20%20%20%20%20%20%20%20%20limit%3A%2050000%0A%20%20%20%20%20%20%20%20%20%20meta%3A%20null%20%20%23%20this%20seems%20to%20get%20both%20meta%20and%20non-meta%20posts%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%29%20%7B%0A%20%20%20%20%20%20%20%20results%20%7B%0A%20%20%20%20%20%20%20%20%20%20user%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20username%0A%20%20%20%20%20%20%20%20%20%20%20%20slug%0A%20%20%20%20%20%20%20%20%20%20%20%20displayName%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D
xx = json.loads(d)
aa = []
count = 0
for y in xx["data"]["posts"]["results"]:
count += 1
y = y["user"]
#people tend to use full names on LessWrong but not HN - cleaning data so that the most-likely-to-actually-be-used-for-HN usernames are picked
if y and y["username"] == y["slug"] == y["displayName"] and y["username"] not in aa:
aa.append(y["username"])
print(count)
print(len(aa))
z = {}
null = []
exceptions = []
for p in aa:
#wonderful non-ratelimited hacker news API
pp = requests.get(f"https://hacker-news.firebaseio.com/v0/user/{p}.json").text
print(p)
if pp == 'null':
null.append(p)
else:
try:
l = json.loads(pp)
z[p] = l["karma"]
except:
exceptions.append(p)
print(len(z))
print(z)
zz = {k:v for (k, v) in z.items() if v > 1}
print(len(zz))
print(zz)
print(len(null))
print(null)
print(len(exceptions))
print(exceptions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment