Пример #1
0
def show():
    # 读取文件
    d = path.dirname(__file__)
    text = open(path.join(d, 'doc//countdata.txt'),encoding='gbk').read()
    # 若是中文文本,则先进行分词操作
    text = chnSegment.word_segment(text)
    # 生成词云
    plotWordcloud.generate_wordcloud(text)
    return plotWordcloud
Пример #2
0
def stu_word_cloud_create(req):
    text = ','.join(req.get("data"))
    # 分词
    try:
        text = chnSegment.word_segment(text)
        # 生成词云
        image_path = plotWordcloud.generate_wordcloud(text)
    except ValueError:
        print("词云处理错误")
        return "0"
    else:
        return image_path
Пример #3
0
# coding:utf-8
import time
from os import path
import chnSegment
import plotWordcloud


if __name__=='__main__':

    # 读取文件
    start = time.time()
    d = path.dirname(__file__)
    text = open(path.join(d, u'doc//lunwen.txt'), 'r', encoding='utf8').read()
    # text = open(path.join(d,'doc//alice.txt')).read()
    #  text="毕业快乐"

    # 若是中文文本,则先进行分词操作
    text=chnSegment.word_segment(text)
    # 生成词云
    plotWordcloud.generate_wordcloud(text)
    end = time.time()
    print(1)
Пример #4
0
                    f.writelines(line)
                    f.write('\n')
        return filename


if __name__ == '__main__':
    bv = 'BV1wD4y1o7AS'
    # 查看历史弹幕必须先登录,需要发送cookies,请到浏览器登录B站,然后复制cookies
    cookie_str = """sid=8vd13q70; DedeUserID=352344482; DedeUserID__ckMd5=6fd10e5604fdd0f8; SESSDATA=6d229ed3%2C1605761169%2C81fa2*51; bili_jct=4bf80916780eef006feb26a006f9fa92; LIVE_BUVID=AUTO1715902091706163; rpdid=|(YuRJRJRkk0J'ulmukR|kkl; _uuid=D0210717-E454-7B0C-2119-692BF553A92302306infoc; buvid3=E147F691-0ECC-61E1-13CB-53DC1EF5EB1447081infoc; CURRENT_QUALITY=80; blackside_state=1; CURRENT_FNVAL=80; bfe_id=fdfaf33a01b88dd4692ca80f00c2de7f"""
    headers['cookie'] = cookie_str
    # 根据BV号获取cid,视频可能有分P,需考虑
    cid_data_list = get_cid(bv)
    # 获取所有历史弹幕的日期
    date_history_list = get_date_history(cid_data_list)
    # 根据日期获取当天的弹幕
    fileName = get_all_dan_mu(date_history_list, bv)

    # 以下是生成词云图片。图片样式在plotWordcloud.py配置

    # 读取文件
    d = path.dirname(__file__)
    text = open(path.join(d, f'doc//{fileName}.txt'),
                encoding='utf-8',
                errors='ignore').read()

    # 若是中文文本,则先进行分词操作
    text = chnSegment.word_segment(text)

    # 生成词云
    plotWordcloud.generate_wordcloud(text, fileName)
# coding:utf-8

from os import path
import plotWordcloud
import sys

if __name__ == '__main__':
    arg1 = sys.argv[1]
    arg2 = sys.argv[2]

    plotWordcloud.generate_wordcloud(arg1, arg2)

    print(arg1)