示例#1
0
def create_type_specific_record(resource):
    """
    Obtain data pertaining to either a Book or Movie resource and write data to
    either the Book.csv file or the Movie.csv file.
    
    Parameters:
        resource (Resource): Resource object; either Book or Movie
    """
    
    if resource["Type"] == "book":
            
        # Get book data
        book = get_book(resource["UID"])
               
        # Obtain correct csv file path for books
        file_path = get_csv_path("Book.csv")
        
        # Write resource record
        write_dict_to_csv(file_path, book, 'a')
        
    else:
        
        # Get movie data
        movie = get_movie(resource["UID"])
        
        # Obtain correct csv file path for movies
        file_path = get_csv_path("Movie.csv")
    
        # Write resource record
        write_dict_to_csv(file_path, movie, 'a')
示例#2
0
def write_resource_record(resource):
    """
    Writes one record to the Resources.csv file.
    
    Parameters:
        resource_list(Resource): Resource object; either Book or Movie
    """
    
    # Obtain correct csv file path for resources
    file_path = get_csv_path("Resource.csv")
    
    # Write resource record
    write_dict_to_csv(file_path, resource, 'a')
示例#3
0
def write_keywords_record(resource):
    """
    Obtain a list of keywords for the resource and write to Keywords CSV file.
    
    Parameters:
        resource (Resource): Resource object; either Book or Movie
    """
    
    # Get keywords for resource
    keywords = get_keywords()
    
    # Obtain correct csv file path for resources
    file_path = get_csv_path("Keywords.csv")
    
    # Write resource record
    write_list_to_csv(file_path, keywords, resource["UID"], 'a')
示例#4
0
def get_movies():
    """
    Creates and returns a list of lists from Movie.csv where all sublists are
    the rows in the csv file. The first sublist is the column names present in
    Movie.csv.
    
    Returns:
        movie_list (list): List that contains sublists of each row in the
        Movie.csv file
    """
    # Obtain the file path for Book.csv which contains records for all
    # resources
    csv_path = get_csv_path("Movie.csv")

    #Obtain the list of books
    movie_list = get_list_from_csv(csv_path)

    return movie_list
示例#5
0
def write_names_record(resource, name_type):
    """
    Writes inidividual names with UID to appropriate csv files which would
    either be Cast.csv or Writers.csv.
    
    Parameters:
        resource (Resource): Resource object; either Book or Movie
        name_type (string): The type of name (writers or cast)
    """
    
    print("\n{0}".format(name_type.upper()))
    
    names = get_names()
    
    # Obtain correct csv file path for cast
    file_path = get_csv_path(name_type.capitalize() + ".csv")

    # Write resource record
    write_list_to_csv(file_path, names, resource["UID"], 'a')
示例#6
0
def write_resources_to_csv_files(resource_list):
    """ 
    Write resource list parameter to appropriate CSV files.
    
    Parameters:
        resource_list (list): List of Resource objects; either Book or Movie
        
    Returns:
        (bool): Whether the CSV files were modified
    """
    
    # Obtain resource csv file path
    resource_file_path = get_csv_path("Resource.csv")
    
    # Write to resource csv file
    write_resource_csv(resource_file_path, resource_list)
    
    # Obtain keywords csv file path
    keywords_file_path = get_csv_path("Keywords.csv")
    
    # Write keywords to csv file
    write_keywords_csv(keywords_file_path, resource_list)
    
    # Obtain book csv file path
    book_file_path = get_csv_path("Book.csv")
    
    # Write book data to csv dile
    write_book_csv(resource_list, book_file_path)
    
    # Obtain movie csv file path
    movie_file_path = get_csv_path("Movie.csv")
    
    # Write movie data to csv file
    write_movie_csv(resource_list, movie_file_path)
    
    # Obtain cast csv file path
    cast_file_path = get_csv_path("Cast.csv")
    
    # Write cast data to csv file
    write_cast_csv(resource_list, cast_file_path)
    
    # Obtain writers csv file path
    writers_file_path = get_csv_path("Writers.csv")
    
    # Write cast data to csv file
    write_writers_csv(resource_list, writers_file_path)
示例#7
0
def get_cast():
    """
    Creates and returns a list of lists from Cast.csv where all sublists are
    the rows for each UID. 
    
    The first sublist is the column names: UID and keywords
    
    Returns:
        (list): List of sublists that contains the UID at index 0 
        and associated writers at subsequent indexes
    """
    # Obtain the file path for Cast.csv which contains records for all
    # resources
    csv_path = get_csv_path("Cast.csv")

    #Obtain the list of cast members
    lst = get_list_from_csv(csv_path)

    # Obtain the list of UIDs without duplicates
    uid_list = get_uids_from_list(lst)

    # Obtain and return a list of cast members assocaited with a UID
    return associate_uid_with_list(lst, uid_list)
示例#8
0
def get_keywords():
    """
    Creates and returns a list of lists from keywords.csv where all sublists are
    the rows for each UID. 
    
    The first sublist is the column names: UID and keywords
    
    Returns:
        (list): List of sublists that contains the UID at index 0 
        and associated keywords at subsequent indexes 
    """

    # Obtain the file path for Keywords.csv which contains records for all
    # resources
    csv_path = get_csv_path("Keywords.csv")

    #Obtain the list of keywords
    lst = get_list_from_csv(csv_path)

    # Determine UIDs present in lst
    uid_list = get_uids_from_list(lst)

    # Obtain and return a list of UIDs associated with each keyword
    return associate_uid_with_list(lst, uid_list)
示例#9
0
def get_resources(resource_type):
    """
    Returns a list of resources where each row of the csv file is a sublist of 
    the resource list.
    
    The columns in the csv file are repsent in the first sublist.
    
    Parameters:
        resource_type (string): The type of resource the resource list
        should contain
    
    Returns:
        resource_list (list): List that contains sublists for each row in the
        Resource.csv file
    """

    # Obtain the file path for Resource.csv which contains records for all
    # resources
    csv_path = get_csv_path("Resource.csv")

    # Obtain a list of resources
    resource_list = get_list_from_csv(csv_path, resource_type)

    return resource_list