From f6b6185fb213bc055abf9fdd1f32e2f008c3a94a Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 12 Nov 2022 12:40:14 +0700 Subject: [PATCH] rename ta_comment index, implement get comments from es --- tubearchivist/home/src/es/index_mapping.json | 2 +- tubearchivist/home/src/index/comments.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tubearchivist/home/src/es/index_mapping.json b/tubearchivist/home/src/es/index_mapping.json index bed6973c..4a325eae 100644 --- a/tubearchivist/home/src/es/index_mapping.json +++ b/tubearchivist/home/src/es/index_mapping.json @@ -462,7 +462,7 @@ } }, { - "index_name": "comments", + "index_name": "comment", "expected_map": { "youtube_id": { "type": "keyword" diff --git a/tubearchivist/home/src/index/comments.py b/tubearchivist/home/src/index/comments.py index 05f9a6ed..a7423ee4 100644 --- a/tubearchivist/home/src/index/comments.py +++ b/tubearchivist/home/src/index/comments.py @@ -16,13 +16,13 @@ class Comments: def __init__(self, youtube_id): self.youtube_id = youtube_id - self.es_path = f"ta_comments/_doc/{youtube_id}" + self.es_path = f"ta_comment/_doc/{youtube_id}" self.max_comments = "all,100,all,30" self.json_data = False def build_json(self): """build json document for es""" - comments_raw = self.get_comments() + comments_raw = self.get_yt_comments() comments_format = self.format_comments(comments_raw) self.json_data = { @@ -53,7 +53,7 @@ class Comments: return yt_obs - def get_comments(self): + def get_yt_comments(self): """get comments from youtube""" print(f"comments: get comments with format {self.max_comments}") yt_obs = self.build_yt_obs() @@ -99,3 +99,12 @@ class Comments: def delete_comments(self): """delete comments from es""" _, _ = ElasticWrap(self.es_path).delete() + + def get_es_comments(self): + """get comments from ES""" + response, statuscode = ElasticWrap(self.es_path).get() + if statuscode == 404: + print(f"comments: not found {self.youtube_id}") + return False + + return response