Skip to content

Commit

Permalink
Merge pull request #54 from RileyXX/improvements-for-imdb-requests-an…
Browse files Browse the repository at this point in the history
…d-print-statements

Improvements for IMDB requests and printing item status
  • Loading branch information
RileyXX authored Jun 27, 2023
2 parents bea44c4 + c329798 commit 205c77a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
14 changes: 7 additions & 7 deletions IMDBTraktSyncer/IMDBTraktSyncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def filter_by_comment_length(lst, min_comment_length=None):

for item in trakt_watchlist_to_set:
item_count += 1
print(f" - Adding item ({item_count} of {num_items}): {item['Title']} ({item['Year']}) to Trakt Watchlist")
imdb_id = item['IMDB_ID']
media_type = item['Type'] # 'movie', 'show', or 'episode'

Expand Down Expand Up @@ -200,9 +201,8 @@ def filter_by_comment_length(lst, min_comment_length=None):
})

response = EH.make_trakt_request(url, payload=data)
if response:
print(f" - Adding item ({item_count} of {num_items}): {item['Title']} ({item['Year']}) to Trakt Watchlist")
else:

if response is None:
error_message = f"Failed to add item ({item_count} of {num_items}): {item['Title']} ({item['Year']}) to Trakt Watchlist"
print(f" - {error_message}")
EL.logger.error(error_message)
Expand Down Expand Up @@ -391,6 +391,7 @@ def filter_by_comment_length(lst, min_comment_length=None):

for review in trakt_reviews_to_set:
item_count += 1
print(f" - Submitting comment ({item_count} of {num_items}): {review['Title']} ({review['Year']}) on Trakt")
imdb_id = review['IMDB_ID']
comment = review['Comment']
media_type = review['Type'] # 'movie', 'show', or 'episode'
Expand Down Expand Up @@ -421,9 +422,8 @@ def filter_by_comment_length(lst, min_comment_length=None):
}

response = EH.make_trakt_request(url, payload=data)
if response:
print(f" - Submitted comment ({item_count} of {num_items}): {review['Title']} ({review['Year']}) on Trakt")
else:

if response is None:
error_message = f"Failed to submit comment ({item_count} of {num_items}): {review['Title']} ({review['Year']}) on Trakt"
print(f" - {error_message}")
EL.logger.error(error_message)
Expand Down Expand Up @@ -538,7 +538,7 @@ def filter_by_comment_length(lst, min_comment_length=None):
response = EH.make_trakt_request(remove_url, payload=data)

if response is None:
error_message = f"Error removing {item['Type']} ({item_count} of {num_items}): {item['Title']} ({item['Year']}) from Trakt Watchlist"
error_message = f"Failed removing {item['Type']} ({item_count} of {num_items}): {item['Title']} ({item['Year']}) from Trakt Watchlist"
print(f" - {error_message}")
EL.logger.error(error_message)

Expand Down
15 changes: 6 additions & 9 deletions IMDBTraktSyncer/errorHandling.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,16 @@ def get_page_with_retries(url, driver, wait, total_wait_time=180, initial_wait_t
try:
driver.get(url)

# Wait until the page has finished loading
wait.until(EC.presence_of_element_located((By.TAG_NAME, 'body')))
# Wait until the status code becomes available
wait.until(lambda driver: driver.execute_script(
"return window.performance.getEntries().length > 0 && window.performance.getEntries()[0].responseStatus !== undefined"
))

# Get the HTTP status code of the page using JavaScript
status_code = driver.execute_script(
"""
var xhr = new XMLHttpRequest();
xhr.open('GET', window.location.href, false);
xhr.send(null);
return xhr.status;
"""
"return window.performance.getEntries()[0].responseStatus;"
)

# Check for any error codes
if status_code is None:
return True, status_code, url # Unable to determine page loaded status
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
with codecs.open(os.path.join(here, "README.md"), 'r', encoding="utf-8") as fh:
long_description = "\n" + fh.read()

VERSION = '1.5.2'
VERSION = '1.5.4'
DESCRIPTION = 'A python script that syncs user watchlist, ratings and comments for Movies, TV Shows and Episodes both ways between Trakt and IMDB.'

# Setting up
Expand Down

0 comments on commit 205c77a

Please sign in to comment.