Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCLC API "Python" Format like JSON? #2

Open
tomhohenstein opened this issue Jan 4, 2016 · 0 comments
Open

OCLC API "Python" Format like JSON? #2

tomhohenstein opened this issue Jan 4, 2016 · 0 comments

Comments

@tomhohenstein
Copy link
Contributor

From Tim - moved here from learn-git

I have been successful in running an OCLC API via python to generate a list of ISSN’s associated with a list of inputted ISSNs.
This has been very useful, and replaces a tool that used to be available through SFX.

I was able to do this be taking the data in a .csv format, and manipulating that data by appending it to Python lists, all of which is close to what I would have done with PHP arrays.

But I GOT CURIOUS over another format the OCLC offers called “python”. This looks a lot like the json format you are using.

So here’s my problem. I can REPRODUCE a return for a single issn api request as follows by copying and pasting the return into a python script and calling it “a”:

a={
'stat':'ok',
'group':[{
'rel':'this',
'list':[{
'issn':'0193-5615',
'form':'JB'},
{
'issn':'1559-9167',
'form':'JB'},
{
'issn':'1548-1409',
'form':'JD'},
{
'issn':'1937-4402',
'form':'JD'}]}]}

I can then parse this in a variety of ways:

For example:

print(((a['group'][0])['list'][3])['issn'])

will render 1937-4402

or a more complicated process:

b=(a['group'][0])
c=(b['list'])
l=len(c)

for i in range(l):
print(c['issn'])

will render a list of all 4 of the ISSN’s in the above output.

My problem is that I cannot for the life of me figure out how to actually generate the above (a) return as a single value using Python. This would be essential in making it possible form e to iterate through a list of inputted ISSN’s as I can do now using the OCLC .csv format.

The best I can do is get Python to write this out by doing the following:

url='http://xissn.worldcat.org/webservices/xid/issn/2161-9417?method=getForms&format=python'

x = urllib.request.urlopen(url)
print(x)

for t in x:
t1 = str( t, encoding='utf8' )
print(t1)

This writes the same result out in the results, but NOT as a single parsable value.
Anything I do to compile this print into single array of any sort gets me an error when I try to parse by searching on a key value, by insisting that key values must be in an integer form.

I keep thinking that there is something really obvious that I am missing here.

Tim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant