rename ta_comment index, implement get comments from es

This commit is contained in:
simon 2022-11-12 12:40:14 +07:00
parent 5b7e3e877b
commit f6b6185fb2
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 13 additions and 4 deletions

View File

@ -462,7 +462,7 @@
}
},
{
"index_name": "comments",
"index_name": "comment",
"expected_map": {
"youtube_id": {
"type": "keyword"

View File

@ -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