From e96d14dd21f934a80494fc00328ad6dfad6f9061 Mon Sep 17 00:00:00 2001 From: kpt <2817151932@qq.com> Date: Wed, 3 Jul 2024 20:16:50 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90getTopicPageData=E3=80=91=E8=AF=9D?= =?UTF-8?q?=E9=A2=98=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/getTopicPageData.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 utils/getTopicPageData.py diff --git a/utils/getTopicPageData.py b/utils/getTopicPageData.py new file mode 100644 index 0000000..1e066a2 --- /dev/null +++ b/utils/getTopicPageData.py @@ -0,0 +1,28 @@ +from utils.getPublicData import * + +def getTopicLen(topic):# 统计特定话题下的评论数目 + commentsList = getAllCommentsData() + topic_len = 0 + for i in commentsList: + if i[9] == topic: + topicLen+=1 + return topic_len + +def getTopicPageCreatedAtCharData(topic):# 统计包含特定热词的评论在每个日期的数量,并返回日期和对应的评论数量 + commentsList = getAllCommentsData() + createdAt = {} + for i in commentsList: + if i[9]==topic: + if i[1] in createdAt.keys(): + createdAt[i[1]] += 1 + else: + createdAt[i[1]] = 1 + return list(createdAt.keys()),list(createdAt.values()) + +def getCommentFilterData(topic):# 筛选包含特定热词的评论并返回这些评论的数据 + commentsList = getAllCommentsData() + commentData = [] + for i in commentsList: + if i[9] == topic: + commentData.append(i) + return commentData \ No newline at end of file