Skip to content

Commit

Permalink
Updated [examples/search.py]
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzeman committed Mar 31, 2015
1 parent cee7302 commit 158b9be
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions examples/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@
logging.basicConfig(level=logging.DEBUG)

from trakt import Trakt
from trakt.objects import Season, Episode


def print_lookup(id, service):
print "Trakt['search'].lookup(%r, %r)" % (id, service)

item = Trakt['search'].lookup(id, service)

if type(item) is Episode and item.show:
sk, ek = item.pk
print "\t%s (%s) - S%02dE%02d %r" % (item.show.title, item.show.year, sk, ek, item.title)
else:
print "\t%s (%s)" % (item.title, item.year)


def print_query(query, media=None, year=None):
print "Trakt['search'].query(%r, %r, %r)" % (query, media, year)

items = Trakt['search'].query(query, media, year)

for item in items:
if type(item) is Episode and item.show:
sk, ek = item.pk
print "\t[%.2d%%] %s (%s) - S%02dE%02d %r" % (item.score, item.show.title, item.show.year, sk, ek, item.title)
else:
print "\t[%.2d%%] %s (%s)" % (item.score, item.title, item.year)


if __name__ == '__main__':
# Configure
Expand All @@ -12,12 +39,11 @@
)

# Lookup by id
l_movie = Trakt['search'].lookup('tt0848228', 'imdb')
l_show = Trakt['search'].lookup('tt0903747', 'imdb')
l_episode = Trakt['search'].lookup('tt0959621', 'imdb')
print_lookup('tt0848228', 'imdb')
print_lookup('tt0903747', 'imdb')
print_lookup('tt0959621', 'imdb')

# Search by name
s_movie = Trakt['search'].query('The Avengers', 'movie')
s_show = Trakt['search'].query('Breaking Bad', 'show')

pass
print_query('The Avengers', 'movie')
print_query('Breaking Bad', 'show')
print_query('Breaking Bad', 'episode')

0 comments on commit 158b9be

Please sign in to comment.