Esempio n. 1
0
def my_friend_sharing(msg):  #定义函数 ,当有msg发送过来,则用requests模块获取该网址
    msg_sharing = requests.get('msg.url')  #这里就是获取msg的网址信息了
    doc = pq(msg_sharing.text)  #解析HTML代码
    msg_content = doc('#js_content').text()  #提取文本
    msg_result = stats_word.cn(msg_content, 10)  #引用模块统计处理文本

    plt.rcdefaults()  #恢复到缺省的配置(matplotlib载入时从配置文件读入的配置)?
    fig, ax = plt.subplots()  #初始化,面向对象画图。在图表中创建子图fig.ax   fig画布 ax对象

    plt.rcParams['font.sans-serif'] = ['SimHei']  #引入汉字输入功能
    dict_result = dict(msg_result)  #字典化了那个统计结果列表,应该直接可转吧
    x_val = []  #空列表
    y_val = []  #空列表
    for keys, values in dict_result:  #分别提取统计结果的键和数量值
        x_val.append(keys)
        y_val.append(values)

    y_pos = np.arange(len(x_val))  #y——pos的范围设定为0到xv的个数
    error = np.random.rand(len(x_val))  #error为在len(x_val)范围内的随机数?

    ax.barh(
        y_pos, y_val, xerr=error, align='center'
    )  #绘制一个width为y_pos即10,bottom为y_val的横向条形图,xerr=error是什么意思?align为设定子图居于有值的视窗中间
    ax.set_yticks(y_pos)  #设定y轴上的值个数,本案例为10(每个刻度线都是一个ytick对象)
    ax.set_yticklabels(x_val)  #设定y轴刻度标签设定为x_val内的数据,本案例即排在前10的10个词
    ax.invert_yaxis()  #y轴反向?从横向转为正向? (官方说明:labels read top-to-bottom)
    ax.set_xlabel('高频词')  #设置y轴的标题
    ax.set_ylabel('出现次数')  #设置x轴的标题
    ax.set_title('词频统计表')  #设置图形的标题
    plt.savefig("词频统计图.png")  #把该图另存为“词频统计图。png”,分辨率为默认值

    msg.reply_image("词频统计图.png")  #12节wxpy模块的运用,记不太清了,见过
Esempio n. 2
0
def my_friend_sharing(msg):  #定义函数 ,当有msg发送过来,则用requests模块获取该网址
    msg_sharing = requests.get('msg.url')  #这里就是获取msg的网址信息了
    doc = pq(msg_sharing.text)  #解析HTML代码
    msg_content = doc('#js_content').text()  #提取文本
    msg_result = stats_word.cn(meg_content, 100)  #引用模块统计处理文本
    msg_result_str = str(msg_result)  #返回信息处理结果
    my_friend.send(msg_result_str)  #向好友发送该结果
Esempio n. 3
0
def my_friend_sharing(msg):  #定义函数 ,当有msg发送过来,则用requests模块获取该网址
    msg_sharing = requests.get('msg.url')  #这里就是获取msg的网址信息了
    doc = pq(msg_sharing.text)  #解析HTML代码
    msg_content = doc('#js_content').text()  #提取文本
    msg_result = stats_word.cn(msg_content, 10)  #引用模块统计处理文本

    plt.rcdefaults()  #固定语法,啥意思???
    fig, ax = plt.subplots()  #固定语法,引入图层???
    plt.rcParams['font.sans-serif'] = ['SimHei']  #引入汉字输入功能
    dict_result = dict(msg_result)  #字典化了那个统计结果列表,应该直接可转吧
    x_val = []  #空列表
    y_val = []  #空列表
    for keys, values in dict_result:  #分别提取统计结果的键和数量值
        x_val.append(keys)
        y_val.append(values)
    y_pos = np.arange(len(x_val))  #y轴的范围设定为0到xv的个数???
    error = np.random.rand(len(x_val))  #啥意思???

    ax.barh(y_pos, y_val, xerr=error, align='center'
            )  #设置一个y轴为y_pos,x轴为y_val的条形图,xerr不知控制什么,align为设定子图居于有值的视窗中间
    ax.set_yticks(y_pos)  #设定y轴上的值个数,本案例为10
    ax.set_yticklabels(x_val)  #y轴上各个节点的标签设定为x_val内的数据,本案例即排在前10的10个汉字
    ax.invert_yaxis()  #标签由上至下读取???
    ax.set_xlabel('高频汉字')  #设置y轴的标题
    ax.set_ylabel('出现次数')  #设置x轴的标题
    ax.set_title('词频统计表')  #设置图形的标题
    plt.savefig("词频统计图.png")  #应该是把该图另存为“词频统计图。png”,这个在刚才的网搜没搜到

    msg.reply_image("词频统计图.png")  #12节wxpy模块的运用,记不太清了,见过
Esempio n. 4
0
def main():
    try:
        data=load_file()
        logging.info(data)  #0表示第一个字符
        poems=merge_poems(json.loads(data))
        logging.info('result==>%s',stats_word.cn(poems,100))
    except Exception as e:
        logging.exception(e)
Esempio n. 5
0
from mymodule import stats_word  #读取模块
import json  #引入jsan解码库
import jieba

import getpass  #引入提示代码?此处不太懂。如果要发送邮件,需从哪里输入邮箱信息
sender = input('输入发件人邮箱:')
password = getpass.getpass('输入发件人邮箱密码(可复制粘贴):')
recipients = input('输入收件人邮箱:')

import requests  #引入requests库
r = requests.get(
    'https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA')  #用get语法直接获取网页HTML代码

from pyquery import PyQuery as pq  #引入pyquery库
doc = pq(r.text)  #用pq()语法解析网页的HTML代码
content = doc('#js_content').text()  #引入提示代码?此处完全不懂该语法原理。得到文字文本
result = stats_word.cn(content, 100)  #用stats——word模块的函数处理文本,筛选出词频最高的100个词
result_str = str(result)  #将结果转为字符串

import yagmail  #插入yagmail库
yag = yagmail.SMTP(sender, password, host='smtp.qq.com')  #链接邮箱服务器。此处不懂为何有问题?
yag.send(recipients, '[1901010115]自学训练营DAY11 游业鹏',
         result_str)  #设定接收人、标题、内容信息后,发送
import json

path = r'D:\Documents\GitHub\selfteaching-python-camp\exercises\1901010059\day10\tang300.json'
with open(path, 'r', encoding='UTF-8') as f:
    a = f.read()

from mymodule.stats_word import stats_text_cn as cn

print(cn(a, 20))
#任选一个函数用a测试参数类型检测是否成功
Esempio n. 7
0
import json

path = r'D:\Documents\GitHub\selfteaching-python-camp\exercises\1901010059\day09\tang300.json'
with open(path, 'r', encoding='UTF-8') as f:
    a = f.read()

from mymodule.stats_word import stats_text_cn as cn

print(cn(a, 100))
#任选一个函数用a测试参数类型检测是否成功
Esempio n. 8
0
a = ('happy', 'happy', 'happy', '哈哈哈')

from mymodule.stats_word import stats_text_cn as cn
try:  #添加一个try except 捕获异常
    cn(a)
except ValueError as Type_Error:
    print(Type_Error)
print(cn(a))
#任选一个函数用a测试参数类型检测是否成功
Esempio n. 9
0
old. Evening the young boy offered his help eagerly.
Summer went by and winter came. It took Yugong and his crew a full
year to travel back and forth once.
On the bank of the Yellow River dwelled an old man much respected
for his wisdom. When he saw their back-breaking labour, he ridiculed
Yugong saying,”Aren’t you foolish, my friend? You are very old now,
and with whatever remains of your waning strength, you won’t be able
to remove even a corner of the mountain.”
Yugong uttered a sigh and said,”A biased person like you will never
understand. You can’t even compare with the widow’s little boy!”
“Even if I were dead, there will still be my children, my
grandchildren, my great grandchildren, my great great grandchildren.
They descendants will go on forever. But these mountains will not
grow any taler. We shall level them one day!” he declared with
confidence.
The wise old man was totally silenced.
When the guardian gods of the mountains saw how determined Yugong
and his crew were, they were struck with fear and reported the
incident to the Emperor of Heavens.
Filled with admiration for Yugong, the Emperor of Heavens ordered
two mighty gods to carry the mountains away.
'''

with open('tang300.json', mode='r',
          encoding='utf-8') as f:  #创建文件对象f,内容为打开并读取“唐诗300.json文件中的字节”
    read_data = f.read()  #设定字符串read_data,其对应为文件f中的内容
try:
    read_data is isinstance(read_data, str)  #如果取值内容为字符串read_data
    print(stats_word.cn(read_data, 20))  #通过模块内的函数stats_text()罗列字符。
except ValueError:  #如果取值不正确,不是字符串
    print('输入文本为非字符串,请再次检查第68行代码的取值')  #则打印报错提示
Esempio n. 10
0
text = [2, 3, 4, 5]

from mymodule.stats_word import stats_text_cn as cn
try:  #添加一个try except捕获一次
    cn(text)
except ValueError as Type_Error:
    print(Type_Error)
print(cn(a))