I'm doing something similar and I've also encountered some trouble getting acquainted with the api. I'm planning on putting together a tutorial blog post sometime in the near future, here's some of my notes for that put together semi-coherently and mixed with commentary on me working out your problem:
First, here are some very useful blog posts with good examples:
http://josephephillips.com/comic-vine-api-examples-part-1/
http://josephephillips.com/comic_vine_api_examples_part2/
My advice will use the tool jq:
https://stedolan.github.io/jq/
jq is like sed for json, it can pretty print stuff and is a great tool to help to explore the json.
curl -s "http://www.comicvine.com/api/volumes/?api_key=$CVAPI&filter=name:Green Lantern&format=json" > gl.json
This is specifying you want to get /volumes/ info as json, and you are filtering to volumes with the name "Green Lantern". The result is redirected with ">" to gl.json. "-s" is for silent.
This assumes you have your api key in an environment variable called CVAPI
To get a pretty view of this results, do
cat gl.json | jq -C '.' | less
This makes jq pretty print the json and pipe the result to the pager less. "-C" is the flag for colorizing output.
You can observe that the first result is Green Lantern volume 2.
cat gl.json | jq -C '.results[0]' | less
will let you look over this
cat gl.json | jq -C '.results[0] | keys' | less
will let give you a glance of the key values for the volume
One of particular interest is api_detail_url, these are api shortcut urls to help you jump around, let's extract one.
volurl=$(cat gl.json | jq -r '.results[0].api_detail_url')
r is --raw-output, this removes quotes around the url. foo=$( commands ) lets you assign the results of commands into foo.
echo $volurl
http://www.comicvine.com/api/volume/4050-2013/
now you can do
curl -s $volurl"?api_key=$CVAPI&format=json" > glvol.json
to get the info for that volume!
cat glvol.json | jq -C '.results | keys' | less
so we see an issues key
cat glvol.json | jq -C '.results.issues | keys' | less
shows us that this only covers the first 88 issues! So let's go back to the volume info
cat gl.json| jq -C '.results | map({name,description})' | less
this shows us the name and description of all the results allowing you to find the volumes you want.
I hope this is helpful.
Log in to comment