当前位置: 首页>>代码示例>>Python>>正文


Python Movie.save方法代码示例

本文整理汇总了Python中movie.Movie.save方法的典型用法代码示例。如果您正苦于以下问题:Python Movie.save方法的具体用法?Python Movie.save怎么用?Python Movie.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在movie.Movie的用法示例。


在下文中一共展示了Movie.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestMovieClass

# 需要导入模块: from movie import Movie [as 别名]
# 或者: from movie.Movie import save [as 别名]
class TestMovieClass(unittest.TestCase):
    def setUp(self):
        self.m = Movie("Best.Movie.Ever.", 2014, 10)

    def test_get_movie_title(self):
        self.assertEqual("Best.Movie.Ever.", self.m.get_title())

    def test_get_movie_year(self):
        self.assertEqual(2014, self.m.get_year())

    def test_get_movie_rating(self):
        self.assertEqual(10, self.m.get_rating())

    @unittest.skip("This works but no point in generating extra movies.")
    def test_save_movie(self):
        self.assertTrue(self.m.save())
开发者ID:EmilianStankov,项目名称:HackBulgaria,代码行数:18,代码来源:test_movie.py

示例2: MovieCatalogProgram

# 需要导入模块: from movie import Movie [as 别名]
# 或者: from movie.Movie import save [as 别名]
class MovieCatalogProgram():
    def __init__(self):
        self.actors = []
        self.movies = OrderedDict()

        self.db_path = sqlite3.connect("movie_catalog.db")
        self.cursor = self.db_path.cursor()
        self._load_initial_state()

    def add_movie(self):
        self.movie_title = input('title >')
        self.movie_year = input('year >')
        while True:
            self.movie_rating = int(input('rating >'))
            if self.movie_rating <= 10 and self.movie_rating > 0:
                break
            else:
                print("Rating can only be a number between 1 and 10.")
        self.m = Movie(self.movie_title,
                       self.movie_year,
                       self.movie_rating)
        if(self.m.get_title() not in self.movies.keys()
           and self.m.get_year() not in self.movies.values()):
            self.movies[self.movie_title] = self.movie_year
            self.m.save()
            print('{} ({}) {}'.format(self.movie_title,
                                      self.movie_year,
                                      'was added to your catalog!'))
        else:
            print('Movie already exists!')

    def add_actor(self, *arguments):
        arguments = list(arguments)
        if len(arguments) == 1:
            self.name = input('name >')
            self.a = Actor(self.name)
            self.actors.append(self.name)
            arguments.append(len(self.actors))
            self.a.save()
        else:
            if len(self.actors) >= int(arguments[1]):
                self.a = Actor(self.actors[int(arguments[1]) - 1])
            else:
                print("There is no actor with this id! Add new actor!")
                self.name = input('name >')
                self.a = Actor(self.name)
                self.actors.append(self.name)
                self.a.save()
        self.cursor.execute("""CREATE TABLE IF NOT EXISTS relations
                               (movie_id, actor_id)""")
        query = ("INSERT INTO relations(movie_id, actor_id) VALUES (?, ?)")
        data = [int(arguments[0]), int(arguments[1])]
        self.cursor.execute(query, data)
        self.db_path.commit()

    def list_movies(self):
        i = 1
        for movie in self.movies:
            print('[{}] {} ({})'.format(str(i), movie, self.movies[movie]))
            i += 1

    def list_actors(self):
        i = 1
        for actor in self.actors:
            print('[{}] {}'.format(str(i), actor))
            i += 1

    def actor_info(self, id):
        self.__id = id
        movies_ids = []
        movies_actor_is_in = []
        lines = []
        query = ("SELECT Name FROM actors WHERE id = ?")
        data = [self.__id]
        actor = self.cursor.execute(query, data)
        for line in actor:
            actor_name = line[0]
        query = ("SELECT movie_id FROM relations WHERE actor_id = ?")
        for line in self.cursor.execute(query, data):
            movies_ids.append(line[0])
        for i in range(len(movies_ids)):
            query = ("SELECT * FROM movies WHERE id = ?")
            data = [movies_ids[i]]
            movies_actor_is_in.append(self.cursor.execute(query, data))
            for movie_actor_is_in in movies_actor_is_in:
                for line in movies_actor_is_in:
                    for data in line:
                        lines.append(data)
                        break
        print('{} stars in:'.format(actor_name))
        for line in lines:
            print('[{}] {} ({})'.format(line[0], line[1], line[2]))

    def movie_info(self, id):
        self.__id = id
        query = ("SELECT * FROM movies WHERE id = ?")
        data = [self.__id]
        movie = self.cursor.execute(query, data)
        actors_ids = []
        cast = []
#.........这里部分代码省略.........
开发者ID:EmilianStankov,项目名称:HackBulgaria,代码行数:103,代码来源:movie_catalog.py


注:本文中的movie.Movie.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。