Beispiel #1
0
__author__="Mike Chamberlin"
__author__="Bethany Wickham"
__author__="Daniel Zhao"
__date__ ="$Sep 30, 2011 2:52:50 PM$"


from MovieSearch import MovieSearch

session = MovieSearch()
session.search("roadtrip", 200)
Beispiel #2
0
            fd.write(query)

        fd.close()

    # Write delimited data to CSV file
    def writeCsv(self):
        file_name = self.file_name + EXT_CSV
        f_path = os.path.join(self.file_path, file_name)

        data = self.movieList.getString()
        fd = codecs.open(f_path, mode="w", encoding='utf-8')
        fd.write(data)
        fd.close()


if __name__ == '__main__':
    API_KEY = "447ecf40bf72a3fa6218f3024465a567"

    movieNew = Movie()
    movieList = MovieList()
    movieSearch = MovieSearch(API_KEY)
    movieId = movieSearch.getId("Pi")
    movieNew = movieSearch.getDetails(movieId, "credits")
    movieList.setMovie(movieNew)
    movieId = movieSearch.getId("1408")
    movieNew = movieSearch.getDetails(movieId, "credits")
    movieList.setMovie(movieNew)

    tempMovieWrite = MovieWrite("./", "temp", movieList)
    tempMovieWrite.writeCsv()
    tempMovieWrite.writeSql()
Beispiel #3
0
 def __init__(self, api_key, mediaType = "movie"):
     self.movieList = MovieList()
     self.movieSearch = MovieSearch(api_key, mediaType)
     self.titles = []
     self.failed = []
Beispiel #4
0
class MovieDriver:
    
    # Constructor
    def __init__(self, api_key, mediaType = "movie"):
        self.movieList = MovieList()
        self.movieSearch = MovieSearch(api_key, mediaType)
        self.titles = []
        self.failed = []
    
    # Read movie titles from file
    def readFile(self):
        f_path = ""
        while not os.path.isdir(f_path):
            f_path = raw_input("ENTER FILE PATH: ")
            
        print "FILES"
        print "---------------------------"
        
        f_list = os.listdir(f_path)
        for f_name in f_list:
            print f_name

        f_name = ""
        while f_name not in f_list:
            f_name = raw_input("ENTER FILE NAME: ")
        
        print "READING MOVIES TITLES FROM FILE..."
        
        file_path = os.path.join(f_path, f_name)
        fd = open(file_path, "r")
        
        for title in fd.readlines():
            self.titles.append(title.rstrip())
        
        fd.close()
            
    # Read keyboard input
    def readInput(self):
        titleInput = ""

        print "INPUT MOVIE TITLES"        
        while True:
            titleInput = raw_input("(end to exit): ")
            
            if titleInput == 'end':
                break
            
            self.titles.append(titleInput.rstrip())
        
    # Print movie titles        
    def printTitles(self):
        print "MOVIE TITLES:"
        print "---------------------------"
        for title in self.titles:
            print title
        
    # Write movie details to file
    def writeFile(self, toWrite = 'csv'):
        f_path = ""
        while not os.path.isdir(f_path):
            f_path = raw_input("ENTER FILE PATH: ")

        f_name = raw_input("ENTER FILE NAME: ")
        
        movieWrite = MovieWrite(f_path, f_name, self.movieList)
        
        if toWrite == 'csv':
            movieWrite.writeCsv()
        else: 
            movieWrite.writeSql()
            
        if self.failed:   
            fail_name = f_name + EXT_FAIL
            fail_path = os.path.join(f_path, fail_name)
            fd = open(fail_path, "w")
            
            for title in self.failed:
                fd.write(title + "\n")
            
            fd.close()

    # Write movie details to display
    def writeDisplay(self):
        print "ID       TITLE                                                       RELEASE"
        print "-------- ----------------------------------------------------------- ----------"

        tempList = self.movieList.getMovieList()
        for k in tempList:                        
            print "%s %s %s" % (k.getId().rjust(8), (k.getTitle()[0:59].encode('ascii', 'replace')).ljust(59), k.getReleaseDate())
        
    # Search movie details by ID
    def searchId(self, append = None):
        movieNew = Movie()
        
        for movieId in self.titles:
            print "Retrieving for %s..." % movieId
            movieNew = self.movieSearch.getDetails(movieId, append)
            self.movieList.setMovie(movieNew)
    
    # Search movie details by title
    def searchMovies(self, append = None):
        movieNew = Movie()
        
        for name in self.titles:
            prntTitle = (name.rstrip())[0:59]            
            print "Searching for %s..." % prntTitle
            movieId = self.movieSearch.getId(name)
            
            if movieId is not None:
                movieNew = self.movieSearch.getDetails(movieId, append)
                self.movieList.setMovie(movieNew)
            else:
                self.failed.append(name)
Beispiel #5
0
 def __init__(self, api_key, mediaType="movie"):
     self.movieList = MovieList()
     self.movieSearch = MovieSearch(api_key, mediaType)
     self.titles = []
     self.failed = []
Beispiel #6
0
class MovieDriver:

    # Constructor
    def __init__(self, api_key, mediaType="movie"):
        self.movieList = MovieList()
        self.movieSearch = MovieSearch(api_key, mediaType)
        self.titles = []
        self.failed = []

    # Read movie titles from file
    def readFile(self):
        f_path = ""
        while not os.path.isdir(f_path):
            f_path = raw_input("ENTER FILE PATH: ")

        print "FILES"
        print "---------------------------"

        f_list = os.listdir(f_path)
        for f_name in f_list:
            print f_name

        f_name = ""
        while f_name not in f_list:
            f_name = raw_input("ENTER FILE NAME: ")

        print "READING MOVIES TITLES FROM FILE..."

        file_path = os.path.join(f_path, f_name)
        fd = open(file_path, "r")

        for title in fd.readlines():
            self.titles.append(title.rstrip())

        fd.close()

    # Read keyboard input
    def readInput(self):
        titleInput = ""

        print "INPUT MOVIE TITLES"
        while True:
            titleInput = raw_input("(end to exit): ")

            if titleInput == 'end':
                break

            self.titles.append(titleInput.rstrip())

    # Print movie titles
    def printTitles(self):
        print "MOVIE TITLES:"
        print "---------------------------"
        for title in self.titles:
            print title

    # Write movie details to file
    def writeFile(self, toWrite='csv'):
        f_path = ""
        while not os.path.isdir(f_path):
            f_path = raw_input("ENTER FILE PATH: ")

        f_name = raw_input("ENTER FILE NAME: ")

        movieWrite = MovieWrite(f_path, f_name, self.movieList)

        if toWrite == 'csv':
            movieWrite.writeCsv()
        else:
            movieWrite.writeSql()

        if self.failed:
            fail_name = f_name + EXT_FAIL
            fail_path = os.path.join(f_path, fail_name)
            fd = open(fail_path, "w")

            for title in self.failed:
                fd.write(title + "\n")

            fd.close()

    # Write movie details to display
    def writeDisplay(self):
        print "ID       TITLE                                                       RELEASE"
        print "-------- ----------------------------------------------------------- ----------"

        tempList = self.movieList.getMovieList()
        for k in tempList:
            print "%s %s %s" % (k.getId().rjust(8), (k.getTitle()[0:59].encode(
                'ascii', 'replace')).ljust(59), k.getReleaseDate())

    # Search movie details by ID
    def searchId(self, append=None):
        movieNew = Movie()

        for movieId in self.titles:
            print "Retrieving for %s..." % movieId
            movieNew = self.movieSearch.getDetails(movieId, append)
            self.movieList.setMovie(movieNew)

    # Search movie details by title
    def searchMovies(self, append=None):
        movieNew = Movie()

        for name in self.titles:
            prntTitle = (name.rstrip())[0:59]
            print "Searching for %s..." % prntTitle
            movieId = self.movieSearch.getId(name)

            if movieId is not None:
                movieNew = self.movieSearch.getDetails(movieId, append)
                self.movieList.setMovie(movieNew)
            else:
                self.failed.append(name)
Beispiel #7
0
            query = query.rstrip(", ") + ")\n"
            fd.write(query)
        
        fd.close()
       
    # Write delimited data to CSV file
    def writeCsv(self):
        file_name = self.file_name + EXT_CSV
        f_path = os.path.join(self.file_path, file_name)

        data = self.movieList.getString()
        fd = codecs.open(f_path, mode="w", encoding='utf-8')
        fd.write(data)
        fd.close()

if __name__=='__main__':
    API_KEY = "447ecf40bf72a3fa6218f3024465a567"
    
    movieNew = Movie()
    movieList = MovieList()
    movieSearch = MovieSearch(API_KEY)
    movieId = movieSearch.getId("Pi")
    movieNew = movieSearch.getDetails(movieId, "credits")
    movieList.setMovie(movieNew)    
    movieId = movieSearch.getId("1408")
    movieNew = movieSearch.getDetails(movieId, "credits")
    movieList.setMovie(movieNew)
    
    tempMovieWrite = MovieWrite("./", "temp", movieList)   
    tempMovieWrite.writeCsv()
    tempMovieWrite.writeSql()