示例#1
0
    def create_or_update_movie_from_line(self, line):
        movie_parts_separator = "  "

        self.stdout.write(u'Processing line {line}'.format(line=line))

        movie_line_parts = filter(None, (line.split(movie_parts_separator)))

        title = movie_line_parts[3].split("\" (")[0][1:]
        year = movie_line_parts[3].split("\" (")[1][:-2]

        new_or_updated_movie = Movie()
        new_or_updated_movie.imdb_rank = float(movie_line_parts[2])
        new_or_updated_movie.title = title
        new_or_updated_movie.year = year
        new_or_updated_movie.imdb_votes = int(movie_line_parts[1])
        new_or_updated_movie.rating = new_or_updated_movie.imdb_rank
        new_or_updated_movie.total_votes = new_or_updated_movie.imdb_votes
        new_or_updated_movie.save()

        self.stdout.write(unicode(new_or_updated_movie))
        self.stdout.write('')