def test_account_watchlist_movies(self): movietitle = MOVIETITLE acct = tmdb.Account(SESSION_ID) response = acct.info() # to set acct.id kwargs = {'page': 1, 'sort_by': 'created_at.asc'} response = acct.watchlist_movies(**kwargs) self.assertEqual(acct.results[0]['title'], movietitle)
def test_account_watchlist_tv(self): tvtitle = TVTITLE acct = tmdb.Account(SESSION_ID) response = acct.info() # to set acct.id kwargs = {'page': 1, 'sort_by': 'created_at.asc'} response = acct.watchlist_tv(**kwargs) self.assertEqual(acct.results[0]['name'], tvtitle)
def test_account_favorite(self): status_code = SUCCESSFUL_UPDATE acct = tmdb.Account(SESSION_ID) response = acct.info() # to set acct.id kwargs = { 'media_type': 'movie', 'movie_id': FAVORITE_MOVIE_ID, 'favorite': True, } response = acct.favorite(**kwargs) self.assertEqual(acct.status_code, status_code)
def test_account_watchlist(self): status_code = SUCCESSFUL_UPDATE acct = tmdb.Account(SESSION_ID) response = acct.info() # to set acct.id kwargs = { 'media_type': 'movie', 'media_id': WATCHLIST_MEDIA_ID, 'watchlist': 'true', } response = acct.watchlist(**kwargs) self.assertEqual(acct.status_code, status_code)
def authenticate(self): print("Connecting to TMDb db...") tmdb.API_KEY = self.credentials["api_key"] auth = tmdb.Authentication() request_token = auth.token_new()["request_token"] res = auth.token_validate_with_login( request_token=request_token, username=self.credentials["username"], password=self.credentials["password"]) if not res["success"]: raise RuntimeError("TMDb authentication failed") res = auth.session_new(request_token=request_token) if not res["success"]: raise RuntimeError("Could not create new TMDb session") self.account = tmdb.Account(session_id=res["session_id"]) self.account.info()
def test_account_rated_tv(self): acct = tmdb.Account(SESSION_ID) response = acct.info() # to set acct.id kwargs = {'page': 1, 'sort_by': 'created_at.asc'} response = acct.rated_tv(**kwargs) self.assertTrue(hasattr(acct, 'results'))
def test_account_favorite_tv(self): tvtitle = TVTITLE acct = tmdb.Account(SESSION_ID) response = acct.info() # to set acct.id response = acct.favorite_tv() self.assertEqual(acct.results[0]['name'], tvtitle)
def test_account_favorite_movies(self): movietitle = MOVIETITLE acct = tmdb.Account(SESSION_ID) response = acct.info() # to set acct.id response = acct.favorite_movies() self.assertEqual(acct.results[0]['title'], movietitle)
def test_account_lists(self): acct = tmdb.Account(SESSION_ID) response = acct.info() # to set acct.id response = acct.lists() self.assertTrue(hasattr(acct, 'results'))
def test_account_info(self): username = USERNAME acct = tmdb.Account(SESSION_ID) response = acct.info() self.assertEqual(acct.username, username)
def main(): parser = ArgumentParser() parser.add_argument("-i", "--movie-id", dest="movie_id", help="Movie ID to link to") parser.add_argument( "-m", "--movie-name", dest="movie_name", help="Movie name to link to" ) args = parser.parse_args() username = os.getenv('MOVIELINKER_USER') password = os.getenv('MOVIELINKER_PASSWORD') api_key = os.getenv('MOVIELINKER_API') if username is None: home = os.path.expanduser("~") config = configparser.ConfigParser() config_file = os.path.join(home, ".movielinker") if not os.path.isfile(config_file): print("No configuration file found, creating") username = input("What is your TMDB Username? ") password = input("What is your TMDB Password? ") api_key = input("What is your TMDB API Key? ") config["movielinker"] = { "username": username, "password": password, "api_key": api_key, } with open(config_file, "w") as configfile: config.write(configfile) config.read(os.path.join(config_file)) username = config["movielinker"]["username"] password = config["movielinker"]["password"] api_key = config["movielinker"]["api_key"] tmdb.API_KEY = api_key auth = tmdb.Authentication() response = auth.token_new() kwargs = { "request_token": auth.request_token, "username": username, "password": password, } auth = tmdb.Authentication() response = auth.token_validate_with_login(**kwargs) kwargs = {"request_token": auth.request_token} auth = tmdb.Authentication() response = auth.session_new(**kwargs) session_id = response["session_id"] account = tmdb.Account(session_id) response = account.info() response = account.lists() print("\nWhich list contains the movies you have already seen?\n") index = 0 movie_lists = [] for l in response["results"]: print(index, l["name"]) movie_lists.append({"id": l["id"], "name": l["name"]}) index += 1 list_index = int(input()) list_id = movie_lists[list_index]["id"] a = tmdb.Lists(list_id) movie_id = args.movie_id if args.movie_name != None: search = tmdb.Search() response = search.movie(query=args.movie_name) index = 0 foundMovies = [] for s in search.results: foundMovies.append({"id": s["id"], "title": s["title"]}) print(index, s["title"], s["release_date"]) index += 1 movie_index = int(input("\nWhich Movie ID did you mean?\n")) movie_id = foundMovies[movie_index]["id"] print("\nGetting cast list for", foundMovies[movie_index]["title"], "\n") movie = tmdb.Movies(movie_id) collaboratorList = [] index = 0 for c in movie.credits()["cast"]: collaboratorList.append({"id": c["id"], "name": c["name"]}) print(index, c["name"]) index += 1 excluded_collaborator_index = int(input("\nExclude a cast member?\n")) excluded_collaborator = collaboratorList[excluded_collaborator_index] print("Excluding", excluded_collaborator["name"]) response = movie.info() list_response = a.info() seen = set() [seen.add(movie["id"]) for movie in a.items] cache = {} for c in movie.credits()["cast"]: if c["id"] == excluded_collaborator["id"]: continue person = tmdb.People(c["id"]) response = person.info for p in person.movie_credits()["cast"]: if p["vote_count"] < 40: continue if p["id"] in seen: continue if p["id"] in cache: cache[p["id"]]["collaborators"].add(c["name"]) else: p["collaborators"] = {c["name"]} cache[p["id"]] = p filename = "".join(x for x in movie.title if x.isalnum()) + ".csv" with open(filename, "w") as csv_file: fields = [ "id", "title", "collaborators", "vote_average", "vote_count", "release_date", "overview", ] writer = csv.DictWriter(csv_file, fieldnames=fields, extrasaction="ignore") writer.writeheader() for movie in sorted( list(cache.values()), key=lambda x: x["vote_average"], reverse=True ): writer.writerow(movie) # print(str(movie['id']) + ", " + movie['title'] + ", " + str(movie['collaborators']) + ", " + str(movie['vote_average'])) print("complete")
def test_account_rated_tv_episodes(self): account = tmdb.Account(SESSION_ID) account.info() # to set account.id kwargs = {'page': 1, 'sort_by': 'created_at.asc'} account.rated_tv_episodes(**kwargs) self.assertTrue(hasattr(account, 'results'))