Skip to content

Instantly share code, notes, and snippets.

@copperwall
Created December 7, 2014 01:21
Show Gist options
  • Save copperwall/32b69f03cedba87f70f9 to your computer and use it in GitHub Desktop.
Save copperwall/32b69f03cedba87f70f9 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python3
import time
import urllib.request
import json
author = 'pg'
num_posts = 0
base_url = 'https://hacker-news.firebaseio.com/v0/item/'
for itemid in range(1, 100):
# Get item
item_response = urllib.request.urlopen(base_url + str(itemid) + '.json')
response_string = item_response.readall().decode('utf-8')
item = json.loads(response_string)
# Increment number of posts by author if they wrote this post
if item['by'] == author:
num_posts += 1
# No one likes to be rate limited
time.sleep(1)
print('Posts by {:s}: {:d}'.format(author, num_posts))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment