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')
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')
def write_keywords_csv(file_path, resource_list): """ Writes keywords to file at file path parameter from resource list. Parameters: file_path (string): Path to csv file resource_list (list): List of Resource objects; either Book or Movie """ fieldnames = ["UID", "Keywords"] # Write initial row with fieldnames to overwrite file write_list_to_csv(file_path, resource_list[0].keywords, resource_list[0].get_uid(), 'w', fieldnames) for i in range(1, len(resource_list)): write_list_to_csv(file_path, resource_list[i].keywords, resource_list[i].get_uid(), 'a')
def write_writers_csv(resource_list, csv_file): """ Write writers data to Writers.csv file Parameters: resource_list (list): List of resource objects; either Book or Movie csv_file (string): File path to CSV file """ writer_fieldnames = ["UID", "Writers"] # Keep track of whether a record should be written or appended writers_written = False # Loop through each resource for i in range(len(resource_list)): # Test if resource is a movie if resource_list[i].resource_type == "movie": # No record has been written yet if writers_written == False: # Overwrite file file_mode = 'w' else: # Append to end of file file_mode = 'a' # Create list of writers names writers_list = create_names_list(resource_list[i].writers) # Write writers data write_list_to_csv(csv_file, writers_list, resource_list[i].get_uid(), file_mode, writer_fieldnames) writers_written = True