From 2c73522812fdf10d97767245eec29e0725e3cd3d Mon Sep 17 00:00:00 2001 From: bamboo Date: Sat, 14 Sep 2019 00:59:41 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E3=80=901901010132=E3=80=91=E8=87=AA?= =?UTF-8?q?=E5=AD=A6=E8=AE=AD=E7=BB=83=E8=90=A5=E5=AD=A6=E4=B9=A02?= =?UTF-8?q?=E7=BE=A4=20DAY9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @liujiayi0042 作业已完成 --- exercises/1901010132/day9/main.py | 8 ++++ .../1901010132/day9/mymodule/stats_word.py | 42 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 exercises/1901010132/day9/main.py create mode 100644 exercises/1901010132/day9/mymodule/stats_word.py diff --git a/exercises/1901010132/day9/main.py b/exercises/1901010132/day9/main.py new file mode 100644 index 000000000..e2040b402 --- /dev/null +++ b/exercises/1901010132/day9/main.py @@ -0,0 +1,8 @@ +from mymodule import stats_word +import json + +with open(r'\Users\Administrator\Documents\GitHub\selfteaching-python-camp\exercises\1901010132\day9\tang300.json',encoding='UTF-8') as f: + text=f.read() + + +stats_word.stats_text_cn(text, 100) \ No newline at end of file diff --git a/exercises/1901010132/day9/mymodule/stats_word.py b/exercises/1901010132/day9/mymodule/stats_word.py new file mode 100644 index 000000000..7a3c0ab41 --- /dev/null +++ b/exercises/1901010132/day9/mymodule/stats_word.py @@ -0,0 +1,42 @@ +text= ''' +"Her eyes beginning to water, she went on, +"So I would like you all to make me a promise: +from now on, on your way to school, +or on your way home, find something beautiful +to notice. It doesn' t have to be something you +see -it could be a scent perhaps of freshly +baked bread wafting out of someone 's house, +or it could be the sound of the breeze +slightly rustling the leaves in the trees, +or the way the morning light catches one +autumn leaf as it falls gently to the ground. +Please, look for these things, and remember them." +  她的眼睛开始湿润了,她接着说因此我想让你们每个人答应我: +从今以后,在你上学或者放学的路上,要发现一些美丽的事物。 +它不一定是你看到的某个东西——它可能是一种香味—— +也许是新鲜烤面包的味道从某一座房里飘出来,也许是微风轻拂树叶的声音, +或者是晨光照射在轻轻飘落的秋叶上的方式。请你们寻找这些东西并且记住它们吧。 +''' +import re +import collections +count=int() +def stats_text_en(text,count): + if type(text)!=str: + raise ValueError("文本为非字符串") + text=re.sub('[^a-zA-Z]','',text.strip()) #表示所有非英文字母 + text=text.split() + print(collections.Counter(text).most_common(count)) + +def stats_text_cn(text,count): #定义检索中文函数 + if type(text)!=str: + raise ValueError("文本为非字符串") + text=re.sub('[^\u4e00-\u9fa5]','',text) #[^\u4e00-\u9fa5]表示所有非中文 + text=' '.join(text) + text=text.split() + print(collections.Counter(text).most_common(count)) + +def stats_word(text,count): #定义函数,实现统计汉字和英文单词出现次数 + if type(text)!=str: + raise ValueError("文本为非字符串") + stats_text_en(text,count) + stats_text_cn(text,count) From eaed52c9c708e2e40ce95700fc2bfa18b009a291 Mon Sep 17 00:00:00 2001 From: bamboo Date: Sun, 15 Sep 2019 19:03:45 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E3=80=901901010132=E3=80=91=E8=87=AA?= =?UTF-8?q?=E5=AD=A6=E8=AE=AD=E7=BB=83=E8=90=A5=E5=AD=A6=E4=B9=A02?= =?UTF-8?q?=E7=BE=A4=20DAY10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @liujiayi0042 作业已完成 --- exercises/1901010132/day10/main.py | 9 ++++ .../1901010132/day10/mymodule/stats_word.py | 50 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 exercises/1901010132/day10/main.py create mode 100644 exercises/1901010132/day10/mymodule/stats_word.py diff --git a/exercises/1901010132/day10/main.py b/exercises/1901010132/day10/main.py new file mode 100644 index 000000000..beaccbf9d --- /dev/null +++ b/exercises/1901010132/day10/main.py @@ -0,0 +1,9 @@ +from mymodule import stats_word +import json + +with open(r'\Users\Administrator\Documents\GitHub\selfteaching-python-camp\exercises\1901010132\day10\tang300.json',encoding='UTF-8') as f: + read_date = f.read() +try: + print('统计前20的词频数: \n',stats_word.stats_text_cn(read_date,20)) +except ValueError as e: + print(e) \ No newline at end of file diff --git a/exercises/1901010132/day10/mymodule/stats_word.py b/exercises/1901010132/day10/mymodule/stats_word.py new file mode 100644 index 000000000..699c602ef --- /dev/null +++ b/exercises/1901010132/day10/mymodule/stats_word.py @@ -0,0 +1,50 @@ +text= ''' +"Her eyes beginning to water, she went on, +"So I would like you all to make me a promise: +from now on, on your way to school, +or on your way home, find something beautiful +to notice. It doesn' t have to be something you +see -it could be a scent perhaps of freshly +baked bread wafting out of someone 's house, +or it could be the sound of the breeze +slightly rustling the leaves in the trees, +or the way the morning light catches one +autumn leaf as it falls gently to the ground. +Please, look for these things, and remember them." +  她的眼睛开始湿润了,她接着说因此我想让你们每个人答应我: +从今以后,在你上学或者放学的路上,要发现一些美丽的事物。 +它不一定是你看到的某个东西——它可能是一种香味—— +也许是新鲜烤面包的味道从某一座房里飘出来,也许是微风轻拂树叶的声音, +或者是晨光照射在轻轻飘落的秋叶上的方式。请你们寻找这些东西并且记住它们吧。 +''' +import re +import collections +import jieba #结巴中文分词 +count=int() +def stats_text_en(text,count): + if type(text) == str: + b=re.sub(r'[^A-Za-z]',' ',text) + list1=b.split() + return(collections.Counter(list1).most_common(count)) + else: + raise ValueError('文本为非字符串') + +def stats_text_cn(text,count): + if not isinstance(text,str): + raise ValueError('文本为非字符串') + p=re.compile(u'[\u4e00-\u9fa5]') + a=re.findall(p,text) + str2=''.join(a) + seg_list = jieba.cut(str2,cut_all=False) #jieba.cut返回的结构是一个可迭代的生成器generator + newlist=[] + for i in seg_list: + if len(i) >= 2: + newlist.append(i) + return(collections.Counter(newlist).most_common(count)) + +def stats_text(text,count): + if not isinstance(text,str): + raise ValueError('文本为非字符串') + stats_text_cn(text,count) + stats_text_en(text,count) +stats_text(text,count) From a101b0a118582b686ee45ff127c0582a3e305bab Mon Sep 17 00:00:00 2001 From: bamboo Date: Tue, 17 Sep 2019 22:55:43 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E3=80=901901010132=E3=80=91=E8=87=AA?= =?UTF-8?q?=E5=AD=A6=E8=AE=AD=E7=BB=83=E8=90=A5=E5=AD=A6=E4=B9=A02?= =?UTF-8?q?=E7=BE=A4=20DAY11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @liujiayi0042 作业已完成 --- exercises/1901010132/day11/main.py | 27 ++++++++++ .../1901010132/day11/mymodule/stats_word.py | 50 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 exercises/1901010132/day11/main.py create mode 100644 exercises/1901010132/day11/mymodule/stats_word.py diff --git a/exercises/1901010132/day11/main.py b/exercises/1901010132/day11/main.py new file mode 100644 index 000000000..c8112f33c --- /dev/null +++ b/exercises/1901010132/day11/main.py @@ -0,0 +1,27 @@ +import requests +import pyquery +from pyquery import PyQuery +from mymodule import stats_word +import getpass +import yagmail +# 抓取网页 +r = requests.get('https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA') + +# 提取正文 +document = PyQuery(r.text) +content = document('#js_content').text() +print(content) + +#词频统计并转为str类型 +#wordString = ''.join(str(i) for i in wordList) +word_list = stats_word.stats_text_cn(content,100) +word_str = str(word_list) #转换成str类型 +print(word_str) + +#发送统计结果到指定邮箱 +sender = input('请输入发件人邮箱:') +psw = getpass.getpass() #授权码 +recipients = input('输入收件人邮箱:') #指定邮箱pythoncamp@163.com +smtp = "smtp.qq.com" #服务器地址 + +yagmail.SMTP(sender,psw,smtp).send(recipients,'【1901010132】自学训练营学习2群DAY11 bamboo',word_str) \ No newline at end of file diff --git a/exercises/1901010132/day11/mymodule/stats_word.py b/exercises/1901010132/day11/mymodule/stats_word.py new file mode 100644 index 000000000..699c602ef --- /dev/null +++ b/exercises/1901010132/day11/mymodule/stats_word.py @@ -0,0 +1,50 @@ +text= ''' +"Her eyes beginning to water, she went on, +"So I would like you all to make me a promise: +from now on, on your way to school, +or on your way home, find something beautiful +to notice. It doesn' t have to be something you +see -it could be a scent perhaps of freshly +baked bread wafting out of someone 's house, +or it could be the sound of the breeze +slightly rustling the leaves in the trees, +or the way the morning light catches one +autumn leaf as it falls gently to the ground. +Please, look for these things, and remember them." +  她的眼睛开始湿润了,她接着说因此我想让你们每个人答应我: +从今以后,在你上学或者放学的路上,要发现一些美丽的事物。 +它不一定是你看到的某个东西——它可能是一种香味—— +也许是新鲜烤面包的味道从某一座房里飘出来,也许是微风轻拂树叶的声音, +或者是晨光照射在轻轻飘落的秋叶上的方式。请你们寻找这些东西并且记住它们吧。 +''' +import re +import collections +import jieba #结巴中文分词 +count=int() +def stats_text_en(text,count): + if type(text) == str: + b=re.sub(r'[^A-Za-z]',' ',text) + list1=b.split() + return(collections.Counter(list1).most_common(count)) + else: + raise ValueError('文本为非字符串') + +def stats_text_cn(text,count): + if not isinstance(text,str): + raise ValueError('文本为非字符串') + p=re.compile(u'[\u4e00-\u9fa5]') + a=re.findall(p,text) + str2=''.join(a) + seg_list = jieba.cut(str2,cut_all=False) #jieba.cut返回的结构是一个可迭代的生成器generator + newlist=[] + for i in seg_list: + if len(i) >= 2: + newlist.append(i) + return(collections.Counter(newlist).most_common(count)) + +def stats_text(text,count): + if not isinstance(text,str): + raise ValueError('文本为非字符串') + stats_text_cn(text,count) + stats_text_en(text,count) +stats_text(text,count) From e10da68ab1b3379b6a87adf2c277d4641722aa38 Mon Sep 17 00:00:00 2001 From: bamboo Date: Mon, 23 Sep 2019 21:44:21 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E3=80=901901010132=E3=80=91=E8=87=AA?= =?UTF-8?q?=E5=AD=A6=E8=AE=AD=E7=BB=83=E8=90=A5=E5=AD=A6=E4=B9=A02?= =?UTF-8?q?=E7=BE=A4=20DAY12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @liujiayi0042 作业已完成 --- exercises/1901010132/day12/main.py | 21 ++++++++ .../1901010132/day12/mymodule/stats_word.py | 50 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 exercises/1901010132/day12/main.py create mode 100644 exercises/1901010132/day12/mymodule/stats_word.py diff --git a/exercises/1901010132/day12/main.py b/exercises/1901010132/day12/main.py new file mode 100644 index 000000000..692dbac6d --- /dev/null +++ b/exercises/1901010132/day12/main.py @@ -0,0 +1,21 @@ +import requests +from pyquery import PyQuery +from mymodule import stats_word +from wxpy import Bot,Message,embed +#初始化机器人,扫码登陆 +bot = Bot() +#找到好友 +my_friend = bot.friends().search('PrincessAKing')[0] +#发送文本给好友 +my_friend.send('分享任意微信文章给我') +#监听消息 +#回复my_friend的消息 +@bot.register(my_friend) +def reply_my_friend(msg): + if msg.type == 'Sharing': + response = requests.get(msg.url) + document = PyQuery(response.text) + content = document('#js_content').text() + reply = stats_word.stats_text_cn(content,100) + return reply +embed() diff --git a/exercises/1901010132/day12/mymodule/stats_word.py b/exercises/1901010132/day12/mymodule/stats_word.py new file mode 100644 index 000000000..699c602ef --- /dev/null +++ b/exercises/1901010132/day12/mymodule/stats_word.py @@ -0,0 +1,50 @@ +text= ''' +"Her eyes beginning to water, she went on, +"So I would like you all to make me a promise: +from now on, on your way to school, +or on your way home, find something beautiful +to notice. It doesn' t have to be something you +see -it could be a scent perhaps of freshly +baked bread wafting out of someone 's house, +or it could be the sound of the breeze +slightly rustling the leaves in the trees, +or the way the morning light catches one +autumn leaf as it falls gently to the ground. +Please, look for these things, and remember them." +  她的眼睛开始湿润了,她接着说因此我想让你们每个人答应我: +从今以后,在你上学或者放学的路上,要发现一些美丽的事物。 +它不一定是你看到的某个东西——它可能是一种香味—— +也许是新鲜烤面包的味道从某一座房里飘出来,也许是微风轻拂树叶的声音, +或者是晨光照射在轻轻飘落的秋叶上的方式。请你们寻找这些东西并且记住它们吧。 +''' +import re +import collections +import jieba #结巴中文分词 +count=int() +def stats_text_en(text,count): + if type(text) == str: + b=re.sub(r'[^A-Za-z]',' ',text) + list1=b.split() + return(collections.Counter(list1).most_common(count)) + else: + raise ValueError('文本为非字符串') + +def stats_text_cn(text,count): + if not isinstance(text,str): + raise ValueError('文本为非字符串') + p=re.compile(u'[\u4e00-\u9fa5]') + a=re.findall(p,text) + str2=''.join(a) + seg_list = jieba.cut(str2,cut_all=False) #jieba.cut返回的结构是一个可迭代的生成器generator + newlist=[] + for i in seg_list: + if len(i) >= 2: + newlist.append(i) + return(collections.Counter(newlist).most_common(count)) + +def stats_text(text,count): + if not isinstance(text,str): + raise ValueError('文本为非字符串') + stats_text_cn(text,count) + stats_text_en(text,count) +stats_text(text,count) From e922beafc29cf5ea5a808b0a3c042c3a5e6a6e59 Mon Sep 17 00:00:00 2001 From: z47288 <48879194+z47288@users.noreply.github.com> Date: Mon, 18 Nov 2019 23:04:54 +0800 Subject: [PATCH 5/6] =?UTF-8?q?Revert=20"=E3=80=901901010132=E3=80=91?= =?UTF-8?q?=E8=87=AA=E5=AD=A6=E8=AE=AD=E7=BB=83=E8=90=A5=E5=AD=A6=E4=B9=A0?= =?UTF-8?q?2=E7=BE=A4=20DAY11"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit a101b0a118582b686ee45ff127c0582a3e305bab. --- exercises/1901010132/day11/main.py | 27 ---------- .../1901010132/day11/mymodule/stats_word.py | 50 ------------------- 2 files changed, 77 deletions(-) delete mode 100644 exercises/1901010132/day11/main.py delete mode 100644 exercises/1901010132/day11/mymodule/stats_word.py diff --git a/exercises/1901010132/day11/main.py b/exercises/1901010132/day11/main.py deleted file mode 100644 index c8112f33c..000000000 --- a/exercises/1901010132/day11/main.py +++ /dev/null @@ -1,27 +0,0 @@ -import requests -import pyquery -from pyquery import PyQuery -from mymodule import stats_word -import getpass -import yagmail -# 抓取网页 -r = requests.get('https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA') - -# 提取正文 -document = PyQuery(r.text) -content = document('#js_content').text() -print(content) - -#词频统计并转为str类型 -#wordString = ''.join(str(i) for i in wordList) -word_list = stats_word.stats_text_cn(content,100) -word_str = str(word_list) #转换成str类型 -print(word_str) - -#发送统计结果到指定邮箱 -sender = input('请输入发件人邮箱:') -psw = getpass.getpass() #授权码 -recipients = input('输入收件人邮箱:') #指定邮箱pythoncamp@163.com -smtp = "smtp.qq.com" #服务器地址 - -yagmail.SMTP(sender,psw,smtp).send(recipients,'【1901010132】自学训练营学习2群DAY11 bamboo',word_str) \ No newline at end of file diff --git a/exercises/1901010132/day11/mymodule/stats_word.py b/exercises/1901010132/day11/mymodule/stats_word.py deleted file mode 100644 index 699c602ef..000000000 --- a/exercises/1901010132/day11/mymodule/stats_word.py +++ /dev/null @@ -1,50 +0,0 @@ -text= ''' -"Her eyes beginning to water, she went on, -"So I would like you all to make me a promise: -from now on, on your way to school, -or on your way home, find something beautiful -to notice. It doesn' t have to be something you -see -it could be a scent perhaps of freshly -baked bread wafting out of someone 's house, -or it could be the sound of the breeze -slightly rustling the leaves in the trees, -or the way the morning light catches one -autumn leaf as it falls gently to the ground. -Please, look for these things, and remember them." -  她的眼睛开始湿润了,她接着说因此我想让你们每个人答应我: -从今以后,在你上学或者放学的路上,要发现一些美丽的事物。 -它不一定是你看到的某个东西——它可能是一种香味—— -也许是新鲜烤面包的味道从某一座房里飘出来,也许是微风轻拂树叶的声音, -或者是晨光照射在轻轻飘落的秋叶上的方式。请你们寻找这些东西并且记住它们吧。 -''' -import re -import collections -import jieba #结巴中文分词 -count=int() -def stats_text_en(text,count): - if type(text) == str: - b=re.sub(r'[^A-Za-z]',' ',text) - list1=b.split() - return(collections.Counter(list1).most_common(count)) - else: - raise ValueError('文本为非字符串') - -def stats_text_cn(text,count): - if not isinstance(text,str): - raise ValueError('文本为非字符串') - p=re.compile(u'[\u4e00-\u9fa5]') - a=re.findall(p,text) - str2=''.join(a) - seg_list = jieba.cut(str2,cut_all=False) #jieba.cut返回的结构是一个可迭代的生成器generator - newlist=[] - for i in seg_list: - if len(i) >= 2: - newlist.append(i) - return(collections.Counter(newlist).most_common(count)) - -def stats_text(text,count): - if not isinstance(text,str): - raise ValueError('文本为非字符串') - stats_text_cn(text,count) - stats_text_en(text,count) -stats_text(text,count) From 546417a6607b79d58c221cf25f7bf99f0c5038f8 Mon Sep 17 00:00:00 2001 From: z47288 <48879194+z47288@users.noreply.github.com> Date: Wed, 20 Nov 2019 22:05:56 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E3=80=901901010132=E3=80=91=E8=87=AA?= =?UTF-8?q?=E5=AD=A6=E8=AE=AD=E7=BB=83=E8=90=A5=E5=AD=A6=E4=B9=A02?= =?UTF-8?q?=E7=BE=A4=20DAY13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @liujiayi0042 作业已完成 --- exercises/1901010132/day13/main.py | 33 ++++++++++++ .../1901010132/day13/mymodule/stats_word.py | 50 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 exercises/1901010132/day13/main.py create mode 100644 exercises/1901010132/day13/mymodule/stats_word.py diff --git a/exercises/1901010132/day13/main.py b/exercises/1901010132/day13/main.py new file mode 100644 index 000000000..eae28f91c --- /dev/null +++ b/exercises/1901010132/day13/main.py @@ -0,0 +1,33 @@ +from wxpy import Bot,Message,embed + +bot = Bot() +#找到好友 +my_friend = bot.friends().search('PrincessAKing')[0] +#预先注册,利用Bot.register()完成 +#Bot.register(chats=None,msg_types=None,except_self=True,run_async=True,enable=True) +@bot.register(chats = my_friend,msg_types = 'Sharing',except_self = True) +def auto_reply(msg): + import requests + from pyquery import PyQuery +#r = requests.get('https://api.github.com/user', auth=('user', 'pass')) 官方事例 + response = requests.get(msg.url) + document = PyQuery(response.text) + content = document('#js_content').text() + from mymodule.stats_word import stats_text as a + msg1 = dict(a(content,20)) + + import numpy as np + import matplotlib.pyplot as plt + import matplotlib.font_manager as fm + import pandas as pd + from pandas import DataFrame,Series + plt.rcParams['font.sans-serif']=['SimHei'] + group_x = list(msg1.keys()) + group_y = list(msg1.values()) + df = pd.DataFrame(group_y,index = group_x) + df.plot(kind = 'barh') + + plt.savefig('day13.png') + + msg.reply_image('day13.png') +embed() \ No newline at end of file diff --git a/exercises/1901010132/day13/mymodule/stats_word.py b/exercises/1901010132/day13/mymodule/stats_word.py new file mode 100644 index 000000000..699c602ef --- /dev/null +++ b/exercises/1901010132/day13/mymodule/stats_word.py @@ -0,0 +1,50 @@ +text= ''' +"Her eyes beginning to water, she went on, +"So I would like you all to make me a promise: +from now on, on your way to school, +or on your way home, find something beautiful +to notice. It doesn' t have to be something you +see -it could be a scent perhaps of freshly +baked bread wafting out of someone 's house, +or it could be the sound of the breeze +slightly rustling the leaves in the trees, +or the way the morning light catches one +autumn leaf as it falls gently to the ground. +Please, look for these things, and remember them." +  她的眼睛开始湿润了,她接着说因此我想让你们每个人答应我: +从今以后,在你上学或者放学的路上,要发现一些美丽的事物。 +它不一定是你看到的某个东西——它可能是一种香味—— +也许是新鲜烤面包的味道从某一座房里飘出来,也许是微风轻拂树叶的声音, +或者是晨光照射在轻轻飘落的秋叶上的方式。请你们寻找这些东西并且记住它们吧。 +''' +import re +import collections +import jieba #结巴中文分词 +count=int() +def stats_text_en(text,count): + if type(text) == str: + b=re.sub(r'[^A-Za-z]',' ',text) + list1=b.split() + return(collections.Counter(list1).most_common(count)) + else: + raise ValueError('文本为非字符串') + +def stats_text_cn(text,count): + if not isinstance(text,str): + raise ValueError('文本为非字符串') + p=re.compile(u'[\u4e00-\u9fa5]') + a=re.findall(p,text) + str2=''.join(a) + seg_list = jieba.cut(str2,cut_all=False) #jieba.cut返回的结构是一个可迭代的生成器generator + newlist=[] + for i in seg_list: + if len(i) >= 2: + newlist.append(i) + return(collections.Counter(newlist).most_common(count)) + +def stats_text(text,count): + if not isinstance(text,str): + raise ValueError('文本为非字符串') + stats_text_cn(text,count) + stats_text_en(text,count) +stats_text(text,count)