示例#1
0
    def from_json(cls, json_data):
        user = cls(json_data['name'])
        for movie_data in json_data['movies']:
            movie = Movie.from_json(movie_data)
            user.movies.append(movie)

        return user
 def from_json(cls, json_data):
     user = User(json_data["name"])
     movies = []
     for movie in json_data["movies"]:
         movies.append(Movie.from_json(movie))
     user.movies = movies
     return user
示例#3
0
 def from_json(cls, json_data):
     user = cls(json_data['name'])
     movies = []
     for movie_data in json_data['movies']:
         movies.append(Movie.from_json(movie_data))
     user.movies = movies
     return user
示例#4
0
    def from_json(cls, json_data):
        user = cls(json_data['name'])
        movies = []
        for movie_data in json_data['movies']:
            movies.append(Movie.from_json(movie_data))
        user.movies = movies

        return user
    

    # def save_to_file(self):
    #     with open("{}.txt".format(self.name), 'w') as f:
    #         f.write(self.name + '\n')
    #         for movie in self.movies:
    #             f.write("{},{},{}\n".format(movie.name, movie.genre, str(movie.watched)))
    #
    # @classmethod
    # def load_from_file(cls, filename):
    #     with open(filename, 'r') as f:
    #         content = f.readlines()
    #         username = content[0]
    #         movies = []
    #         for line in content[1:]:
    #             movie_data = line.split(',')
    #             movies.append(Movie(movie_data[0], movie_data[1], movie_data[2] == 'True'))
    #
    #         user = cls(username)
    #         user.movies = movies
    #         return user
                
示例#5
0
 def from_json(cls, jsondata):
     user = User(jsondata['name'])
     movies = []
     for movie_data in jsondata['movies']:
         movies.append(Movie.from_json(movie_data))
     user.movies = movies
     print(user)
     return user
示例#6
0
    def from_json(cls, json_data):
        username = json_data['name']
        movies = json_data['movies']

        user = cls(username)
        for movie_data in movies:
            user.movies.append(Movie.from_json(movie_data))
        return user
示例#7
0
    def from_json(cls, json_data):
        user = User(json_data['name'])
        movies = []
        for movie_data in json_data['movies']:
            movies.append(
                Movie.from_json(movie_data))  #append each movie objects
        user.movies = movies

        return user
示例#8
0
    def user_from_json(cls, json_data):
        user_name = json_data['name']
        movies = []

        for movie_data in json_data['movies']:
            movies.append(Movie.from_json(movie_data))

        user = User(user_name)
        user.movies = movies
        return user
示例#9
0
 def log_in_from_json(cls, json_data):
     name = json_data['name']
     movies = json_data['movies']
     new_user = User(name)
     if len(movies) == 0:
         print('No movies were found')
     else:
         for movie in movies:
             new_movie = Movie.from_json(movie)
             new_user.add_movie(new_movie)
     print('Successfully logged-in.')
     return new_user
示例#10
0
 def from_json(cls, json_data):
     '''
     Return the json data in a format to load the data into a new User instance. 
     '''
     user = cls(json_data['name'])  #cls stands for the User class.
     movies = []
     for mov in json_data['movies']:
         movies.append(
             Movie.from_json(mov)
         )  # let the movie handle the json directly with its own method. So the User object doesn't have to be concerned at all about properties of a movie, and if those change.
     user.movies = movies
     return user
示例#11
0
 def from_json(cls, json_data):
     user = User(json_data['name'])
     user.movies = [
         Movie.from_json(movie_data) for movie_data in json_data['movies']
     ]
     return user