From d94d4794da18a929dbfaacbf03f694c160464bb8 Mon Sep 17 00:00:00 2001 From: piw4f8lbj <1836196924@qq.com> Date: Wed, 18 Sep 2024 23:01:10 +0800 Subject: [PATCH] ADD file via upload --- count.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 count.py diff --git a/count.py b/count.py new file mode 100644 index 0000000..899f22b --- /dev/null +++ b/count.py @@ -0,0 +1,36 @@ +import os +import re +from collections import Counter +import pandas as pd + + +#提取txt文件里面的弹幕,并存于列表中 +def read_danmu_files(directory): + danmu_data = [] + for filename in os.listdir(directory): + if filename.endswith('paris_olympics_danmak.txt'): + with open(os.path.join(directory, filename), 'r', encoding='utf-8') as file: + danmu_data.extend(file.readlines()) + return danmu_data + +def count_danmu(): + danmu_data = read_danmu_files('./') # 当前目录下 + #用正则表达式提取含有ai的弹幕 + ai_danmaku = [danmaku for danmaku in danmu_data if + re.search(r'(?