tmdbv3api
tmdbv3api copied to clipboard
Continuous memory increase with this code
from tmdbv3api.exceptions import TMDbException
from tmdbv3api import TMDb, Movie
from lib.Globals import tmdb_api_key
import time
def scrape_from_tmdb_popular(max_pages=500):
tmdb = TMDb()
tmdb.api_key = tmdb_api_key
tmdb_movie = Movie()
while True:
for page in range(1, max_pages):
popular_movies = tmdb_movie.popular(page=page)
for popular_movie in popular_movies:
name, tmdb_id = popular_movie.get('original_title'), popular_movie.get('id')
print(name)
if not name or not tmdb_id:
print(f"Continuing due to no name or tmdb id")
continue
try:
imdb_id = tmdb_movie.external_ids(tmdb_id).get('imdb_id')
except TMDbException:
print(f"Continuing due to no name or imdb id")
continue
except Exception as E:
print(f"Continuing due to other error {E}")
continue
time.sleep(1)
scrape_from_tmdb_popular()
I am using python3.11