Update comments.py

Cleaned up logic, based on what I interpreted from the code: 

Only try to grab new comments from youtube if ES was empty.

Fixed an unexecuted branch compare.
The return inside "if not self.comments_format and es_comments["comment_comments"]:"
could never be reached because of the comparison above it.

Fixed a potential "TypeError: 'bool' object is not subscriptable" due to indexing on es_comments when it is False.

By reducing the number of wasteful calls we can further escape throttling.  
(Although if the intention is to force replacement of old comments with any new ones, then why even query ES?)
This commit is contained in:
Daniel Jue 2024-01-21 13:06:56 -05:00 committed by GitHub
parent 27b6efcab7
commit a01034f291
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -164,18 +164,16 @@ class Comments:
self.check_config() self.check_config()
if not self.is_activated: if not self.is_activated:
return return
# check for existing comments first (could return False).
self.build_json()
if not self.json_data:
return
es_comments = self.get_es_comments() es_comments = self.get_es_comments()
if es_comments and es_comments["comment_comments"]:
if not self.comments_format: # don't overwrite comments in es
return return
if not self.comments_format and es_comments["comment_comments"]: # only try to grab new comments now
# don't overwrite comments in es self.build_json()
if not self.json_data or not self.comments_format:
# we didn't get data or comments
return return
self.delete_comments() self.delete_comments()