Displaying all 4 messages
Randy Stebbing
6/5/2012 at 16:05
I'm just getting back to digging into a problem that I first noticed about a month ago. Can someone verify that they are getting back valid json when doing API calls? Things are fine when I call the api directly from pasting the call in a browser but when I issue basically the exact same call from a python script I get back the raw html text from the web page and not a json formatted key value pairs like I once did.
Private User
6/21/2012 at 13:55
Using api.geni.com or www.geni.com/api ?
The announced new interface api.geni.com are not working anymore, so I had to go back to www.geni.com/api again.
Randy Stebbing
6/27/2012 at 8:40
I've been using https://www.geni.com/api and it is is no longer working for me to return json :(

Here's the relevant code snippet that used to work but it fails on the line in the code that reads. This line used to work.

info = json.loads(response.read())

I'm hoping that when posted this won't strip out the white space in the code below. An additional function takes the returned profiles id's and fetches the desired field of info need for further processing.

--Randy

## project indexer for geni.com

#mechanize will need to be downloaded and installed as a python site package, json is built into python 2.6+
import os, unicodedata, string, time, urllib, datetime
import mechanize
import json

BASE_URL = "https://www.geni.com/api/"

def getProjProfileList(project_number, page_num, count, id_list):
# Returns a list of all profile index numbers included in a project.
# string: projectNumber the last token of any geni project URL is the project number.
# string: pageNum. Passed in as a string. Geni returns multiple pages of 50 names at a time that are part of a project.
# for example an argumetnn of "2" would fetch page 2 or profiles 51-100
# int: count. Calling this proc initially with a count of 0. It will then increment this var each time a profile is
# is read giving you a count of the number of profiles included in the project.
# list of strings: idList. List of the geni id numbers found so far as returned by the API. Initially the list will be empty
# Example: idNums = profile(str(10927), 1, 0, [])

url = BASE_URL + "project-" + project_number + "/profiles" + "?page=" + page_num
try:
response = mechanize.urlopen(url)
#print response.read()
info = json.loads(response.read())
## See http://docs.python.org/library/json.html
if info.has_key('results'):
for cur_item in info['results']:
if cur_item['public']==True:
id = cur_item['id']
count+=1

print str(count) + ": " + str(id)
id_list.append(id.split('-')[-1])

if info.has_key('next_page'):
url = info['next_page']
page_num = url.split('page=')[-1]
getProjProfileList(project_number, page_num, count, id_list)

print "\n"
return id_list
except:
print "Web page communication error. Cannot retrieve Profile list from project # " + project_number
return []
Randy Stebbing
6/27/2012 at 8:42
Boo... it striped out the white space which is critical in python code :(
rails-1a-011