5
Usage: get_first_character "character name"
7
Search for the given name and print the best matching result.
9
# Parameters to initialize the IMDb class.
11
# The used access system. 'web' means that you're retrieving data
12
# from the IMDb web server.
14
#'accessSystem': 'mobile'
15
# XXX: if you've a local installation of the IMDb database,
16
# comment the above line and uncomment the following two.
17
#'accessSystem': 'local',
18
#'dbDirectory': '/usr/local/imdb' # or, in a Windows environment:
19
#'dbDirectory': 'D:/imdb-20060107'
21
# XXX: parameters for a SQL installation.
22
#'accessSystem': 'sql',
23
#'uri': 'mysql://userName:yourPassword@localhost/dbName'
28
# Import the IMDbPY package.
32
print 'You bad boy! You need to install the IMDbPY package!'
36
if len(sys.argv) != 2:
37
print 'Only one argument is required:'
38
print ' %s "character name"' % sys.argv[0]
44
i = imdb.IMDb(**IMDB_PARAMS)
46
in_encoding = sys.stdin.encoding or sys.getdefaultencoding()
47
out_encoding = sys.stdout.encoding or sys.getdefaultencoding()
49
name = unicode(name, in_encoding, 'replace')
51
# Do the search, and get the results (a list of character objects).
52
results = i.search_character(name)
53
except imdb.IMDbError, e:
54
print "Probably you're not connected to Internet. Complete error report:"
59
print 'No matches for "%s", sorry.' % name.encode(out_encoding, 'replace')
62
# Print only the first result.
63
print ' Best match for "%s"' % name.encode(out_encoding, 'replace')
65
# This is a character instance.
66
character = results[0]
68
# So far the character object only contains basic information like the
69
# name; retrieve main information:
72
print character.summary().encode(out_encoding, 'replace')