usign the api for the first time.

Avatar image for wardy277
Wardy277

5

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

Hi,

I am planning on building my own small database of comics that i am reading so i can keep track on ones i have, ones i have read and when the next issue is out etc. I am so glad that there is an api on this site and am very impressed with the extensive api documentation. What I am not sure on is the syntax for limiting. to star, i would like to find the comic that i am reading. I am starting with the green lantern comics for example and would like to find the best way to search the comics I have, say green lantern, then limit it by just the New 52 variants. (I think i am not using the correct naming convention)

Can someone point me in the right direction to list comics, then list their issues. I can probably work out the rest, but just need a starting pointer.

Chris

Avatar image for kstock
kstock

1

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#2  Edited By kstock

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.

Avatar image for wardy277
Wardy277

5

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

thank you very much for the help