On Sat, Apr 28, 2012 at 00:48, Benjamin <benjaminbondt...@gmail.com> wrote:

> I've followed the instructions and populated a mysql db w/ the info from the
> imdb flat files.
> I want to output from this db an xml file for every single imdbpy object
> type(Movie, Person, etc.).
> Is there a way to do this?

Sort of, but I can't guarantee you that it will not be painfully slow. :-)

First of all, you have to know the maximum ID of the object
you're considering (movies, persons, ...)
For movies, you can use something like:
  SELECT MAX(id) FROM title;

After that you can write a Python script to extract the information.
Something like this (beware that it's mostly pseudo-code) should work:

from imdb import IMDb

ia = IMDb('sql', uri='mysql://USERNAME:PASSWORD@localhost/imdb')

for idx in xrange(idx, MAX_ID+1):
    # get the movie object.
    movie = ia.get_movie(idx)
    # fetch all other information, if you need them.
    # ia.update(movie, 'all')
    # or maybe you're only interested in goofs:
    # ia.update(movie, 'goofs')
    # get the XML representation, and do what you want with it.
    xml = movie.asXML()

You better put all the code inside the 'for' cycle in a try/except clause,
since a lot of things can go wrong... just skip to the next item.

A recent suggestion that I want to implement is a JSON output,
but I still had no time to look at it. :-(


Davide Alberani <davide.alber...@gmail.com>  [PGP KeyID: 0x465BFD47]

Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
Imdbpy-help mailing list

Reply via email to