Example #1
0
    titleStartIndex = vals.find("'") + 1
    titleEndIndex = vals.find("', ")
    movie['title'] = vals[titleStartIndex:titleEndIndex]
    vals = vals[(titleEndIndex + 3):]
    vals = vals.split(', ')
    #skip movie haven't seen
    if vals[1] == "'not seen'":
      continue
    movie['year'] = int(vals[0])
    movies.append(movie)
  return movies


if __name__ == '__main__':
  log = open('/home/thayes/Projects/FiLTH/logs/MovieTaggerTest.log', 'w')
  tagger = MovieTagger('/home/thayes/Projects/FiLTH/sql/tag_given_to.sql', '/home/thayes/Projects/FiLTH/sql/tag.sql', log)
  #movies = initMovies(100)
  try:
    #for m in movies:
    #  tagger.promptUserForTag(m['mid'], m['title'], m['year'])
    tagger.promptUserForTag(999999, 'Foo', 1999)
  except (QuitException, KeyboardInterrupt):
    print '\nQUITTING\n'
  finally:
    if tagger.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':
Example #2
0
                        # (i.e. false == creating movie.sql from scratch, true == modifying movie.sql)
  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?
Example #3
0
File: tag.py Project: tgh/FiLTH
  tempFile.write(str(mid))
  tempFile.close()


if __name__ == '__main__':
  try:
    tagGivenToFile = open(TAG_GIVEN_TO_FILENAME, 'a')
    tagFile = open(TAG_FILENAME, 'a')
    logger = open(LOG_FILENAME, 'w')
    tempFile = open(TEMP_FILENAME, 'r')
    movieFile = open(MOVIE_FILENAME, 'r')
  except IOError as e:
    sys.stderr.write("**ERROR: opening file: " + str(e) + ".\n")
    sys.exit()

  movieTagger = MovieTagger(TAG_GIVEN_TO_FILENAME, TAG_FILENAME, logger)

  lastProcessed = tempFile.read()
  log('main', 'last mid processed (read from ' + TEMP_FILENAME + '): ' + lastProcessed)
  lastProcessed = int(lastProcessed)

  #grab all movies seen from movies file
  initMovies(lastProcessed)

  try:
    for movie in movies:
      movieTagger.promptUserForTag(movie['mid'], movie['title'], movie['year'])
      lastProcessed += 1
  except QuitException, KeyboardInterrupt:
    if movieTagger.hasInserts():
      while True: