#!/usr/bin/python import urllib import simplejson base = 'http://whoisi.com/api/' def callAPI(endpoint, **kw): arg = None if kw and len(kw): arg = '?' + urllib.urlencode(kw) u = urllib.urlopen(base + endpoint + arg) return simplejson.loads(u.read()) # get the max id d = callAPI("getMaxPersonID", app="sample") max_person_id = d.get("person_id") print("max person id: %d" % max_person_id) # our final list of people people = dict() # break the requests into 100-person segments and get the people for # each one steps = int(round(max_person_id/100+.9)) start = 1 for i in range(1, (steps+1)): end = min(i * 100, max_person_id) print("getting %d to %d" % (start, end)) d = callAPI("getPeople", app="sample", first=start, last=end) p = d.get("people") for k in p.keys(): people[int(k)] = p.get(k) start += 100 k = people.keys() k.sort() for i in k: p = people.get(i) print("%s - http://whoisi.com/p/%d" % (p.get("name").encode("utf-8"), int(i))) a = p.get("aliases") if len(a): print(" aliases: %s" % a) sites = p.get("sites") if len(sites): sk = sites.keys() sk.sort() for j in sk: s = sites.get(j) t = s.get("title") if t: t = str(t.encode("utf-8")) print(" site: %s" % t) print(" type: %s" % s.get("type")) print(" url: %s" % s.get("url")) print(" feed: %s" % s.get("feed"))