Skip to content

Commit 90612bd

Browse files
committed
Comment time is also updated in the accumulator
1 parent de733a4 commit 90612bd

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

youbot/youtube_utils/youtube_api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ def get_video_comments(self, url: str, search_terms: str = None) -> List:
204204
"like_count":
205205
comment_thread['snippet']['topLevelComment']['snippet'][
206206
'likeCount'],
207-
"reply_count": comment_thread['snippet']['totalReplyCount']}
207+
"reply_count": comment_thread['snippet']['totalReplyCount'],
208+
"comment_time":
209+
comment_thread['snippet']['topLevelComment']['snippet'][
210+
'publishedAt']}
208211
comments.append(current_comment)
209212
except Exception as e:
210213
logger.error(f"Exception in get_video_comments() for {comment_thread}.")

youbot/youtube_utils/youtube_manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,12 @@ def accumulator(self):
169169
exceptions.append(e)
170170
# Update comment data in the DB
171171
for comment_dict in comments:
172+
logger.info(f"Updating comment {comment_dict['url']}")
172173
self.db.update_comment(video_link=comment_dict['url'],
173174
comment_id=comment_dict['comment_id'],
174175
like_cnt=comment_dict['like_count'],
175-
reply_cnt=comment_dict['reply_count'])
176+
reply_cnt=comment_dict['reply_count'],
177+
comment_time=comment_dict['comment_time'])
176178
if len(exceptions) > cnt / 2 and cnt > 0:
177179
logger.error(f"{len(exceptions)} exceptions occurred! "
178180
f"Will only raise the first one.")

youbot/yt_mysql.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def get_channel_by_id(self, ch_id: str) -> Tuple:
130130
ch_id (str): The channel ID
131131
"""
132132

133-
where_statement = f"id='{ch_id}'"
133+
where_statement = f"channel_id='{ch_id}'"
134134
result = self.select_from_table(table=self.CHANNEL_TABLE, where=where_statement)
135135
if len(result) > 1:
136136
logger.warning("Duplicate channel retrieved from SELECT statement:{result}")
@@ -160,7 +160,7 @@ def remove_channel_by_id(self, ch_id: str) -> None:
160160
ch_id (str): The channel ID
161161
"""
162162

163-
where_statement = f"id='{ch_id}'"
163+
where_statement = f"channel_id='{ch_id}'"
164164
self.delete_from_table(table=self.CHANNEL_TABLE, where=where_statement)
165165

166166
def remove_channel_by_username(self, ch_username: str) -> None:
@@ -275,7 +275,8 @@ def get_comments(self, comment_cols: List[str], channel_cols: List[str] = None,
275275

276276
def update_comment(self, video_link: str, comment_id: str = None,
277277
like_cnt: int = None, reply_cnt: int = None,
278-
upload_time: str = None, video_title: str = None) -> None:
278+
upload_time: str = None, video_title: str = None,
279+
comment_time: str = None) -> None:
279280
"""
280281
Populate a comment entry with additional information.
281282
Args:
@@ -285,6 +286,7 @@ def update_comment(self, video_link: str, comment_id: str = None,
285286
reply_cnt:
286287
upload_time:
287288
video_title:
289+
comment_time:
288290
"""
289291

290292
# Get video id
@@ -302,6 +304,8 @@ def update_comment(self, video_link: str, comment_id: str = None,
302304
set_data['like_count'] = like_cnt
303305
if reply_cnt is not None:
304306
set_data['reply_count'] = reply_cnt
307+
if comment_time is not None:
308+
set_data['comment_time'] = comment_time
305309
if upload_time is not None:
306310
set_data['upload_time'] = upload_time
307311
if video_title is not None:

0 commit comments

Comments
 (0)