miri64 / pycomicvine

A wrapper for comicvine.com
MIT License
20 stars 10 forks source link

pycomicvine

A python wrapper for comicvine.com

Build status

Build Status

Installation

Using setuptools you can install pycomicvine as follows:

python setup.py install

Dependencies:

Usage

You can search for resources on comicvine.com.

>>> import pycomicvine
>>> pycomicvine.api_key = "<Your API key>"
>>> pycomicvine.Volume.search("The Walking Dead")
<Volume: The Walking Dead [18166]>

Paramaters are identical to the filters stated in the API Documentation, where resources is omitted. query is mandatory and the first parameter. field_list can be either a list of string or a comma-seperated string.

You can also search mixed resource lists with

>>> pycomicvine.Search("Avengers", field_list=['name','id'])
[<Team: Avengers [3806]>,<Volume: Avengers [7084]>,<Volume: Avengers [33227]>]

Again: all parameters match up with the API Documentation. As you may have guessed Team.search("Teen Titans") is equivalent to Search("Teen Titans", resource="team").

A list of resources of one type can be downloaded using

>>> pycomicvine.Objects(filter="name:Mjolnir")
Objects[<Object: Mjolnir [40971]>,<Object: MJOLNIR Powered Assault Armor [56824]>]

If you know the ID of a resource you can download it directly:

>>> pycomicvine.Character(1807, all=True)
<Character: Superman [1807]>

The additional parameter all assures that all fields of the resource are downloaded. Per default only the ids of resources (and fields that might be via field_list) are downloaded. If a field is not downloaded yet it will be downloaded when it is called.

>>> issue = pycomicvine.Issue(194796)
>>> issue
<Issue: [194796]>
>>> issue.name
'Monster, Part Two'
>>> issue.volume
<Volume: Star Wars: Legacy [18575]>
>>> issue
<Issue: Monster, Part Two [194796]>

The additional parameter do_not_download causes, that nothing is downloaded on initialisation, even if you give a field_list. do_not_download is stronger than all

>>> movie = pycomicvine.Movie(108, all=True, field_list=['name'], do_not_download=True)
>>> movie
<Movie: [108]>
>>> movie.name
'Star Trek'
>>> movie
<Movie: Star Trek [108]>

Here is a mapping of which class is representing which resource type of the API:

Class API resource resource type
Character /character singular resource
Characters /characters list resource
Chat /chat singular resource
Chats /chats list resource
Concept /concept singular resource
Concepts /concepts list resource
Issue /issue singular resource
Issues /issues list resource
Location /location singular resource
Locations /locations list resource
Movie /movie singular resource
Movies /movies list resource
Object /object singular resource
Objects /objects list resource
Origin /origin singular resource
Origins /origins list resource
Person /person singular resource
People /people list resource
Power /power singular resource
Powers /powers list resource
Promo /promo singular resource
Promos /promos list resource
Publisher /publisher singular resource
Publishers /publishers list resource
Search /search list resource
StoryArc /story_arc singular resource
StoryArcs /story_arcs list resource
Team /team singular resource
Teams /teams list resource
Types /types list resource
Video /video singular resource
Videos /videos list resource
VideoType /video_type singular resource
VideoTypes /video_types list resource
Volume /volume singular resource
Volumes /volumes list resource

Type conversion

If you do not like the way we convert the objects, you can always redefine it. pycomicvine gives you the class AttributeDefinition for this:

>>> pycomicvine.Character.gender = pycomicvine.AttributeDefinition('keep')
>>> pycomicvine.Character(20096).gender
2

'keep' is here a keyword to keep the type the JSON gives us. Other possible parameters are the names of our ressource type classes as string and int and datetime.datetime (as there actual types) for conversion into that types. If that is not enough for you, you even can give a function as parameter, that takes a parameter and gives back one return value. You have to define the original type then though. For example:

>>> pycomicvine.Concept.name = pycomicvine.AttributeDefinition(lambda v: "Just another universe" if "universe" in v.lower() else v, start_type=basestring)
>>> pycomicvine.Concept(56089).name
'Just another universe'

Contribute

You can contribute by submitting issue tickets here on GitHub, including Pull Requests. You can test pycomicvine by calling

python setup.py test

License

Copyright (c) 2013 Martin Lenders

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.