Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I wrote python code to process the title.basics.tsv, name.basics.tsv, and title.principles.tsv files from the IMDb (internet movie database) These files can be found at http://www.imdb.com/interfaces/

I wrote python code to process the title.basics.tsv, name.basics.tsv, and title.principles.tsv files from the IMDb (internet movie database) These files can be found at http://www.imdb.com/interfaces/ I wrote python code to print the primary movie titles and names of the principal cast for 20 films (not television shows) chosen at random. My code ensures there are no adult titles in the list. Fields are separated by tab characters, and one record per line. I have the results written to a file named titles.txt

Here is that working python code:

import random # open files  open('name.basics1.tsv', encoding="utf8") moviesfile = open('title.basics1.tsv', encoding="utf8") #counts the total number of lines contained in the specific file def lineCount(fileObject): counter = 0 line = " "  while not line == "": counter += 1 line = fileObject.readline() fileObject.seek(0) return counter # gets data off a specific line of a specific file def getDataOfLine(fileObject, lineNum): counter = 0 line = " "  while not counter == lineNum: counter += 1 line = fileObject.readline() fileObject.seek(0) return line # main function - starts by opening the moviesfile, counting the total number of lines in the file, # and creating an empty array for movies. While the "movies" array is less than 20, # the function will randomly select a line, get the data off that line, and make sure # currMovie is a movie (not a short or TvEpisode) and that it is NOT an adult movie. # If it satisfies these constraints, we will append currMovie data to the movies array.  def main(): moviesfile = open("title.basics1.tsv", encoding="utf8") totalLines = lineCount(moviesfile) movies = [] while not len(movies) == 20: lineNumber = int(random.uniform(1, totalLines)) currMovie = getDataOfLine(moviesfile, lineNumber).split("\t") if currMovie[1] == "movie" and currMovie[4] == "0": movies.append(currMovie) moviesfile.close() # opens the principal cast file  # it then reads the data by lines, splitting them at the tabs,  # and then for currMovie in the array of movies, sees if the  # tconst of title.basics1.tsv file matches the tconst of title.principals1.tsv file  # If they do, we split them with commas and append appropriate tconst id to currMovie   principalCastFile = open("title.principals1.tsv", encoding="utf8") line = " "  while not line == "": line = principalCastFile.readline()[:-1] lineSplit = line.split("\t") for currMovie in movies: if currMovie[0] == lineSplit[0]: currMovie.append(lineSplit[1].split(",")) principalCastFile.close() # opens the castFile and reads the data for the cast, splits info at tabs, and appends each  # of the cast to the appropriate currMovie of the movies array   castFile = open("name.basics1.tsv", encoding="utf8") line = " "  while not line == "": line = castFile.readline() lineSplit = line.split("\t") for currMovie in movies: for cast in currMovie[-1]: if lineSplit[0] == cast: currMovie[-1].append(lineSplit[1]) currMovie[-1].remove(lineSplit[0]) castFile.close() # writes 20 random movies titles (that are not adult movies) along with the principalCast to the titles.txt document   titleAndCastFile = open("titles.txt", 'w') string = ""  for currMovie in movies: string += currMovie[2] for cast in currMovie[-1]: string += "\t" + cast string += " "  titleAndCastFile.write(string) titleAndCastFile.close() # runs main function main() 

I need help adding to my code to write to a second file called actress.txt that lists the complete records of all actresses that appear in my random 20 movie sample from part one. I am supposed to separate the actress records with 20 equal signs. The actress records are located in a very large file (over 7 milllion lines) called actresses.list

I am providing the first several hundred lines of the actresses.list so you know what format this file is in...The code should be able to be written without actually having access to this file.

RULES: 1 Movies and recurring TV roles only, no guest appearances 2 Please submit entries in the format outlined at the end of the list 3 Feel free to submit new actresses

"xxxxx" = a television series "xxxxx" (mini) = a television mini-series [xxxxx] = character name = number to indicate billing position in credits (TV) = TV movie, or made for cable movie (V) = made for video movie (this category does NOT include TV episodes repackaged for video, guest appearances in variety/comedy specials released on video, or self-help/physical fitness videos)

THE ACTRESSES LIST ==================

Name Titles ---- ------ "Steff", Stefanie Oxmann Mcgaha Night of the Demons (2009) (uncredited) [Goth raver] The Bad Lieutenant: Port of Call - New Orleans (2009) (uncredited) [Gambler/Bar patron]

$haniqua "Please Like Me" (2013) {All You Can Eat (#1.4)} [$haniqua the Rabbit] <16> "Please Like Me" (2013) {French Toast (#1.2)} [$haniqua the Rabbit] <12> "Please Like Me" (2013) {Horrible Sandwiches (#1.6)} [$haniqua the Rabbit] <12> "Please Like Me" (2013) {Portuguese Custard Tarts (#1.3)} [$haniqua the Rabbit] <13> "Please Like Me" (2013) {Rhubarb and Custard (#1.1)} [$haniqua the Rabbit] <12> "Please Like Me" (2013) {Spanish Eggs (#1.5)} [$haniqua the Rabbit] <13>

& Ashour, Lucienne A Woman of Distinction (1950) (uncredited) [Apache Dancers] Around the World (1943) (uncredited) [Apache Dancers] Chain Lightning (1950) (uncredited) [Apache Dancers] O-Kay for Sound (1937) [Apache Dancers] "Cabaret" (1936) {(1938-01-12)} [Themselves - Apache Dancers] "Four Star Revue" (1950) {(#1.15)} [Guest Apache Dancers] "Music-Hall" (1949) {(#2.5)} [Themselves] "Variety" (1936) {(1937-06-05)} [Themselves - Dancers]

& Company, Monica Bill Barnes This American Life Live! (2012) (TV) [Dancers]

Álvarez, Michelle Mmesis (2012) [Sonia]

' Betty' Strohfus, Elizabeth Broads & Bombers, a War Time Experiment in Man Power (2016) [Herself]

' Scotty'Gough, Virgina Broads & Bombers, a War Time Experiment in Man Power (2016) [Herself]

'67 Impala "Supernatural" (2005) {99 Problems (#5.17)} (uncredited) [Herself] "Supernatural" (2005) {A Very Supernatural Christmas (#3.8)} (uncredited) [Herself] "Supernatural" (2005) {Abandon All Hope (#5.10)} (uncredited) [Herself] "Supernatural" (2005) {After School Special (#4.13)} (uncredited) [Herself] "Supernatural" (2005) {All Dogs Go to Heaven (#6.8)} (uncredited) [Herself] "Supernatural" (2005) {All Hell Breaks Loose: Part 1 (#2.21)} (uncredited) [Herself] "Supernatural" (2005) {All Hell Breaks Loose: Part 2 (#2.22)} (uncredited) [Herself] "Supernatural" (2005) {And Then There Were None (#6.16)} (uncredited) [Herself] "Supernatural" (2005) {Appointment in Samarra (#6.11)} (uncredited) [Herself] "Supernatural" (2005) {Are You There, God? It's Me, Dean Winchester (#4.2)} (uncredited) [Herself] "Supernatural" (2005) {Asylum (#1.10)} (uncredited) [Herself] "Supernatural" (2005) {Bad Day at Black Rock (#3.3)} (uncredited) [Herself] "Supernatural" (2005) {Bedtime Stories (#3.5)} (uncredited) [Herself] "Supernatural" (2005) {Bloodlust (#2.3)} (uncredited) [Herself] "Supernatural" (2005) {Bloody Mary (#1.5)} (uncredited) [Herself] "Supernatural" (2005) {Born Under a Bad Sign (#2.14)} (uncredited) [Herself] "Supernatural" (2005) {Bugs (#1.8)} (uncredited) [Herself] "Supernatural" (2005) {Caged Heat (#6.10)} (uncredited) [Herself] "Supernatural" (2005) {Changing Channels (#5.8)} (uncredited) [Herself] "Supernatural" (2005) {Children Shouldn't Play with Dead Things (#2.4)} (uncredited) [Herself] "Supernatural" (2005) {Clap Your Hands If You Believe (#6.9)} (uncredited) [Herself] "Supernatural" (2005) {Criss Angel Is a Douche Bag (#4.12)} (uncredited) [Herself] "Supernatural" (2005) {Croatoan (#2.9)} (uncredited) [Herself] "Supernatural" (2005) {Crossroad Blues (#2.8)} (uncredited) [Herself] "Supernatural" (2005) {Dark Side of the Moon (#5.16)} (uncredited) [Herself] "Supernatural" (2005) {Dead in the Water (#1.3)} (uncredited) [Herself] "Supernatural" (2005) {Dead Man's Blood (#1.20)} (uncredited) [Herself] "Supernatural" (2005) {Dead Men Don't Wear Plaid (#5.15)} (uncredited) [Herself] "Supernatural" (2005) {Death Takes a Holiday (#4.15)} (uncredited) [Herself] "Supernatural" (2005) {Devil's Trap (#1.22)} (uncredited) [Herself] "Supernatural" (2005) {Dream a Little Dream of Me (#3.10)} (uncredited) [Herself] "Supernatural" (2005) {Everybody Loves a Clown (#2.2)} (uncredited) [Herself] "Supernatural" (2005) {Exile on Main St. (#6.1)} (uncredited) [Herself] "Supernatural" (2005) {Faith (#1.12)} (uncredited) [Herself] "Supernatural" (2005) {Fallen Idols (#5.5)} (uncredited) [Herself] "Supernatural" (2005) {Family Matters (#6.7)} (uncredited) [Herself] "Supernatural" (2005) {Family Remains (#4.11)} (uncredited) [Herself] "Supernatural" (2005) {Folsom Prison Blues (#2.19)} (uncredited) [Herself] "Supernatural" (2005) {Free to Be You and Me (#5.3)} (uncredited) [Herself] "Supernatural" (2005) {Fresh Blood (#3.7)} (uncredited) [Herself] "Supernatural" (2005) {Frontierland (#6.18)} (uncredited) [Herself] "Supernatural" (2005) {Ghostfacers (#3.13)} (uncredited) [Herself] "Supernatural" (2005) {Good God, Y'All (#5.2)} (uncredited) [Herself] "Supernatural" (2005) {Hammer of the Gods (#5.19)} (uncredited) [Herself] "Supernatural" (2005) {Heart (#2.17)} (uncredited) [Herself] "Supernatural" (2005) {Heaven and Hell (#4.10)} (uncredited) [Herself] "Supernatural" (2005) {Hell House (#1.17)} (uncredited) [Herself] "Supernatural" (2005) {Hollywood Babylon (#2.18)} (uncredited) [Herself] "Supernatural" (2005) {Home (#1.9)} (uncredited) [Herself] "Supernatural" (2005) {Hook Man (#1.7)} (uncredited) [Herself] "Supernatural" (2005) {Houses of the Holy (#2.13)} (uncredited) [Herself] "Supernatural" (2005) {Hunted (#2.10)} (uncredited) [Herself] "Supernatural" (2005) {I Believe the Children Are Our Future (#5.6)} (uncredited) [Herself] "Supernatural" (2005) {I Know What You Did Last Summer (#4.9)} (uncredited) [Herself] "Supernatural" (2005) {In My Time of Dying (#2.1)} (uncredited) [Herself] "Supernatural" (2005) {In the Beginning (#4.3)} (uncredited) [Herself] "Supernatural" (2005) {It's a Terrible Life (#4.17)} (uncredited) [Herself] "Supernatural" (2005) {It's the Great Pumpkin, Sam Winchester (#4.7)} (uncredited) [Herself] "Supernatural" (2005) {Jump the Shark (#4.19)} (uncredited) [Herself] "Supernatural" (2005) {Jus in Bello (#3.12)} (uncredited) [Herself] "Supernatural" (2005) {Lazarus Rising (#4.1)} (uncredited) [Herself] "Supernatural" (2005) {Let It Bleed (#6.21)} (uncredited) [Herself] "Supernatural" (2005) {Like a Virgin (#6.12)} (uncredited) [Herself] "Supernatural" (2005) {Live Free or Twihard (#6.5)} (uncredited) [Herself] "Supernatural" (2005) {Long Distance Call (#3.14)} (uncredited) [Herself] "Supernatural" (2005) {Lucifer Rising (#4.22)} (uncredited) [Herself] "Supernatural" (2005) {Malleus Maleficarum (#3.9)} (uncredited) [Herself] "Supernatural" (2005) {Mannequin 3: The Reckoning (#6.14)} (uncredited) [Herself] "Supernatural" (2005) {Metamorphosis (#4.4)} (uncredited) [Herself] "Supernatural" (2005) {Mommy Dearest (#6.19)} (uncredited) [Herself] "Supernatural" (2005) {Monster Movie (#4.5)} (uncredited) [Herself] "Supernatural" (2005) {My Bloody Valentine (#5.14)} (uncredited) [Herself] "Supernatural" (2005) {My Heart Will Go On (#6.17)} (uncredited) [Herself] "Supernatural" (2005) {Mystery Spot (#3.11)} (uncredited) [Herself] "Supernatural" (2005) {Nightmare (#1.14)} (uncredited) [Herself] "Supernatural" (2005) {Nightshifter (#2.12)} (uncredited) [Herself] "Supernatural" (2005) {No Exit (#2.6)} (uncredited) [Herself] "Supernatural" (2005) {No Rest for the Wicked (#3.16)} (uncredited) [Herself] "Supernatural" (2005) {On the Head of a Pin (#4.16)} (uncredited) [Herself] "Supernatural" (2005) {Phantom Traveler (#1.4)} (uncredited) [Herself] "Supernatural" (2005) {Pilot (#1.1)} (uncredited) [Herself] "Supernatural" (2005) {Playthings (#2.11)} (uncredited) [Herself] "Supernatural" (2005) {Point of No Return (#5.18)} (uncredited) [Herself] "Supernatural" (2005) {Provenance (#1.19)} (uncredited) [Herself] "Supernatural" (2005) {Red Sky at Morning (#3.6)} (uncredited) [Herself] "Supernatural" (2005) {Roadkill (#2.16)} (uncredited) [Herself] "Supernatural" (2005) {Route 666 (#1.13)} (uncredited) [Herself] "Supernatural" (2005) {Salvation (#1.21)} (uncredited) [Herself] "Supernatural" (2005) {Sam, Interrupted (#5.11)} (uncredited) [Herself] "Supernatural" (2005) {Scarecrow (#1.11)} (uncredited) [Herself] "Supernatural" (2005) {Sex and Violence (#4.14)} (uncredited) [Herself] "Supernatural" (2005) {Shadow (#1.16)} (uncredited) [Herself] "Supernatural" (2005) {Simon Said (#2.5)} (uncredited) [Herself] "Supernatural" (2005) {Sin City (#3.4)} (uncredited) [Herself] "Supernatural" (2005) {Skin (#1.6)} (uncredited) [Herself] "Supernatural" (2005) {Something Wicked (#1.18)} (uncredited) [Herself] "Supernatural" (2005) {Swan Song (#5.22)} (uncredited) [Herself] "Supernatural" (2005) {Swap Meat (#5.12)} (uncredited) [Herself] "Supernatural" (2005) {Sympathy for the Devil (#5.1)} (uncredited) [Herself] "Supernatural" (2005) {Tall Tales (#2.15)} (uncredited) [Herself] "Supernatural" (2005) {The Benders (#1.15)} (uncredited) [Herself] "Supernatural" (2005) {The Curious Case of Dean Winchester (#5.7)} (uncredited) [Herself] "Supernatural" (2005) {The Devil You Know (#5.20)} (uncredited) [Herself] "Supernatural" (2005) {The End (#5.4)} (uncredited) [Herself] "Supernatural" (2005) {The French Mistake (#6.15)} (uncredited) [Herself] "Supernatural" (2005) {The Kids Are Alright (#3.2)} (uncredited) [Herself] "Supernatural" (2005) {The Man Who Would Be King (#6.20)} (uncredited) [Herself] "Supernatural" (2005) {The Monster at the End of This Book (#4.18)} (uncredited) [Herself] "Supernatural" (2005) {The Rapture (#4.20)} (uncredited) [Herself] "Supernatural" (2005) {The Real Ghostbusters (#5.9)} (uncredited) [Herself] "Supernatural" (2005) {The Song Remains the Same (#5.13)} (uncredited) [Herself] "Supernatural" (2005) {The Third Man (#6.3)} (uncredited) [Herself] "Supernatural" (2005) {The Usual Suspects (#2.7)} (uncredited) [Herself] "Supernatural" (2005) {Time Is on My Side (#3.15)} (uncredited) [Herself] "Supernatural" (2005) {Two and a Half Men (#6.2)} (uncredited) [Herself] "Supernatural" (2005) {Two Minutes to Midnight (#5.21)} (uncredited) [Herself] "Supernatural" (2005) {Unforgiven (#6.13)} (uncredited) [Herself] "Supernatural" (2005) {Weekend at Bobby's (#6.4)} (uncredited) [Herself] "Supernatural" (2005) {Wendigo (#1.2)} (uncredited) [Herself] "Supernatural" (2005) {What Is and What Should Never Be (#2.20)} (uncredited) [Herself] "Supernatural" (2005) {When the Levee Breaks (#4.21)} (uncredited) [Herself] "Supernatural" (2005) {Wishful Thinking (#4.8)} (uncredited) [Herself] "Supernatural" (2005) {Yellow Fever (#4.6)} (uncredited) [Herself] "Supernatural" (2005) {You Can't Handle the Truth (#6.6)} (uncredited) [Herself]

'Barry' Vincent, Mabel Broads & Bombers, a War Time Experiment in Man Power (2016) [Herself]

'Dot' Lewis, Dorthy Broads & Bombers, a War Time Experiment in Man Power (2016) [Herself]

'Electric Nana'. Vzquez, Mnica "El hormiguero" (2006) {(2011-03-23)} [Herself]

'Gaby' Goff, Mary Welcome to My Darkside! (2009) [Herself]

'Ink'Albritton, Felicia "Underground" (2016) {(#2.1)} [Gullah Slave]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions