Example #1
0
    def _read_row(self, row: _ROW, id_: int) -> Movie:
        """
        Helper method to construct a Movie from a row.

        Raises:
            ValueError: unable to parse row: {row}
         """
        error = False

        try:
            title = row['Title']
            genres = [
                self._get_genre(Genre(name))
                for name in row['Genre'].split(',')
            ]
            description = row['Description']
            director = self._get_director(Director(row['Director']))
            actors = [
                self._get_actor(Actor(name))
                for name in row['Actors'].split(',')
            ]
            release_year = int(row['Year'])
            runtime_minutes = int(row['Runtime (Minutes)'])
            rating = float(row['Rating'])
            votes = int(row['Votes'])
            revenue_millions = float(
                row['Revenue (Millions)']
            ) if row['Revenue (Millions)'] != 'N/A' else None
            metascore = int(
                row['Metascore']) if row['Metascore'] != 'N/A' else None
        except KeyError:
            error = True
        except ValueError:
            error = True

        if error:
            raise ValueError(f'unable to parse row: {row}')

        movie = Movie(title, release_year, id_)
        movie.genres = genres
        movie.description = description
        movie.director = director
        movie.actors = actors
        movie.runtime_minutes = runtime_minutes
        movie.rating = rating
        movie.votes = votes

        if revenue_millions:
            movie.revenue_millions = revenue_millions

        if metascore:
            movie.metascore = metascore

        return movie
Example #2
0
def populated_movies(genres, directors, actors):
    movies = []

    for i in range(10):
        movie = Movie(f'Movie{i}', 2000 + i, i)
        movie.genres = [genres[i]]
        movie.description = f'Description{i}'
        movie.director = directors[i]
        movie.actors = [actors[i]]
        movie.runtime_minutes = i + 1
        movie.rating = float(i)
        movie.votes = i

        if i % 2 == 0:
            movie.revenue_millions = float(i + 1)

        if i % 4 == 0:
            movie.metascore = i * 10

        movies.append(movie)

    return movies