當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。