Created
December 7, 2014 01:21
-
-
Save copperwall/32b69f03cedba87f70f9 to your computer and use it in GitHub Desktop.
This file contains 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 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