#!/usr/bin/env python from MovieCrew import MovieCrew from QuitException import QuitException import traceback if __name__ == '__main__': log = open('/home/thayes/Projects/FiLTH/logs/MovieCrewTest.log', 'w') movieCrew = None try: movieCrew = MovieCrew('/home/thayes/Projects/FiLTH/sql/worked_on.sql', '/home/thayes/Projects/FiLTH/sql/crew_person.sql', log) movies = [(1063, 'Michael Clayton', 2007), (792, 'Il Postino', 1997), (1460, 'Shawshank', 1994)] for movie in movies: movieCrew.promptUserForCrewPerson(movie[0], movie[1], movie[2]) except QuitException: print '\nQUITTING\n' except Exception as e: print '\n***EXCEPTION!***' traceback.print_exc() finally: if movieCrew: if movieCrew.hasInserts(): while True: response = raw_input('\nThere are still unwritten sql insert statements. Write them out? ').lower() if response not in ['y','n']: print "Only 'y'/'n'\n" continue if response == 'y': movieCrew.writeCrewInsertsToFile(open('/home/thayes/Projects/FiLTH/sql/crew_person.sql', 'a')) movieCrew.writeWorkedOnInsertsToFile(open('/home/thayes/Projects/FiLTH/sql/worked_on.sql', 'a'))
retVal = 0 #value to return to shell tagger = None #MovieTagger object crewHandler = None #MovieCrew object f = None #file holder #process the command-line arguments inputFile, isUpdate = processArgs() #open the input file to read from try: _log = open(_logFile, 'w') #setup a tagger and crew person handler only if in update mode if isUpdate: tagger = MovieTagger(TAG_GIVEN_TO_SQL_FILE, TAG_SQL_FILE, _log) crewHandler = MovieCrew(WORKED_ON_SQL_FILE, CREW_PERSON_SQL_FILE, _log) _nextMid = getNextMid() else: _nextMid = 1 #iterate over the lines retrieved from the file for line in getLinesFromFile(inputFile): lg('main', 'current movie: "' + line + '"') title, year, stars, mpaa, country = getMovieData(line) if not isUpdate: #we are not updating existing sql file (i.e. we are starting from scratch), so just add an INSERT statement from the movie data _inserts.append(INSERT_FORMAT_STRING.format(_nextMid, title, year, stars, mpaa, country, 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL')) else: #are we updating an existing movie rather than adding a new one? isNew, mid = isNewMovie(title, year, stars, mpaa, country.replace("'",""))
if __name__ == '__main__': try: tagGivenToFile = open(TAG_GIVEN_TO_SQL_FILE, 'a') tagFile = open(TAG_SQL_FILE, 'a') logger = open(LOG_FILENAME, 'w') tempFile = open(TEMP_FILENAME, 'r+') movieFile = open(MOVIE_SQL_FILE, 'r') crewpersonFile = open(CREW_PERSON_SQL_FILE, 'a') workedOnFile = open(WORKED_ON_SQL_FILE, 'a') except IOError as e: sys.stderr.write("**ERROR: opening file: " + str(e) + ".\n") sys.exit() movieTagger = MovieTagger(TAG_GIVEN_TO_SQL_FILE, TAG_SQL_FILE, logger) crewHandler = MovieCrew(WORKED_ON_SQL_FILE, CREW_PERSON_SQL_FILE, logger) #gather optional movie ids from command-line mids = processArgs() #no mids given on command-line--use "last processed" movie id if len(mids) == 0: lastProcessed = tempFile.read() log('main', 'last mid processed (read from ' + TEMP_FILENAME + '): ' + lastProcessed) lastProcessed = int(lastProcessed) #grab all movies seen from movies file after "last processed" initMovies(lastProcessed) #process only the requested movies with the given ids else: log('main', 'mids: ' + str(mids)) initRequestedMovies(mids)