Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: cbe3dafe46
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 24 lines (18 sloc) 0.689 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/usr/bin/env python

"""
This script fetches the total counts by year and persists them to js/all.js
Since this results in a query for every year, it's nice about waiting a
second between requests.
"""

import time
import json
import requests

counts = {}
url = 'http://chinkapin.pti.indiana.edu:9994/solr/select/?qt=sharding&wt=json&q=publishDate:%s'

for year in range(1600, 2013):
    r = requests.get(url % year, headers={"user-agent": "hathitime: https://github.com/edsu/hathitime"})
    j = json.loads(r.content)
    counts[str(year)] = j["response"]["numFound"]
    print year
    time.sleep(1)

open("js/all.js", "w").write("allCounts = " + json.dumps(counts, indent=2) + ";")
Something went wrong with that request. Please try again.