From 7a3b573f2ff8b0808b40159ef6eb2d31f63404ab Mon Sep 17 00:00:00 2001 From: Zezhou-Sun <894101858@qq.com> Date: Fri, 8 Nov 2019 20:34:26 +0800 Subject: [PATCH 1/4] d11 --- exercises/1901010161/1001S02E03_calculator.py | 6 +-- exercises/1901010161/d11/00.py | 38 +++++++++++++++++++ exercises/1901010161/d11/1111.code-workspace | 8 ++++ exercises/1901010161/d11/main.py | 12 ++++++ .../1901010161/d11/mymodule/stats_word.py | 35 +++++++++++++++++ 5 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 exercises/1901010161/d11/00.py create mode 100644 exercises/1901010161/d11/1111.code-workspace create mode 100644 exercises/1901010161/d11/main.py create mode 100644 exercises/1901010161/d11/mymodule/stats_word.py diff --git a/exercises/1901010161/1001S02E03_calculator.py b/exercises/1901010161/1001S02E03_calculator.py index 51fc809ec..2607f5ae5 100644 --- a/exercises/1901010161/1001S02E03_calculator.py +++ b/exercises/1901010161/1001S02E03_calculator.py @@ -7,13 +7,9 @@ def calculate(): / for division ''') -#<<<<<<< master +# <<<<<<< master number_1 = float(input('Please enter the first number: ')) number_2 = float(input('Please enter the second number: ')) -#======= - number_1 = int(input('Please enter the first number: ')) - number_2 = int(input('Please enter the second number: ')) -#>>>>>>> master if operation == '+': print('{} + {} = '.format(number_1, number_2)) diff --git a/exercises/1901010161/d11/00.py b/exercises/1901010161/d11/00.py new file mode 100644 index 000000000..965cb9f6e --- /dev/null +++ b/exercises/1901010161/d11/00.py @@ -0,0 +1,38 @@ +import requests +import getpass +import yagmail +from pyquery import PyQuery as py +from mymodule import stats_word + +reponse = requests.get('https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA') # 网页请求 +web_text = reponse.text # 保存更多网页文本数据 +document = py(web_text) +content = document('#js_content').text() +print('content=', content) + +w_list = stats_word.stats_text_cn(content, 100) +w_list = str(w_list) +print(w_list) + +sender = input("请输入发件人邮箱:") +password = getpass.getpass("输入发件人邮箱授权码:") + +yagmail.register(sender, password) + +yag = yagmail.SMTP(sender, password, host='smtp.qq.com') +yag.send('pythoncamp@163.com', '【1901010161】自学训练营学习2群DAY11 Zezhou-Sun', w_list) +print("发送成功") + +''' +countlist_str = ''.join(str(i) for i in countlist) +print(countlist_str) +# Use getpass to enter the email address related information +import getpass +sender = input('894101858@qq.com') ##'Enter the email address of sender:' +password = getpass.getpass('kdkrtqtbtazubdef') ##'Enter the password of the email from sender:' +recipients = input('pythoncamp@163.com') ##'Enter the email address of the reciever:' +# Leverage yagmail to send out emai +import yagmail +yag = yagmail.SMTP(user=sender, password=password, host='smtp.qq.com') +yag.send(recipients, '【1901010161】自学训练营学习2群DAY11 Zezhou-Sun', countlist_str) +''' diff --git a/exercises/1901010161/d11/1111.code-workspace b/exercises/1901010161/d11/1111.code-workspace new file mode 100644 index 000000000..a4fe0a37c --- /dev/null +++ b/exercises/1901010161/d11/1111.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "D:\\用户目录\\我的文档\\GitHub\\selfteaching-python-camp\\exercises\\1901010161" + } + ], + "settings": {} +} \ No newline at end of file diff --git a/exercises/1901010161/d11/main.py b/exercises/1901010161/d11/main.py new file mode 100644 index 000000000..4288af16f --- /dev/null +++ b/exercises/1901010161/d11/main.py @@ -0,0 +1,12 @@ +from mymodule import stats_word + +path = r'd:\用户目录\我的文档\GitHub\selfteaching-python-camp\exercises\1901010161\d11\mymodule\tang300.json' +with open(path, 'r', encoding='UTF-8') as f: # byte编码的类型名称是 UTF-8 + + read_date = f.read() + + +try: + print('出现频率最高的前20个词: \n', stats_word.stats_text_cn(read_date, 20)) +except ValueError: + print('ValueError:type of argument is not string!') diff --git a/exercises/1901010161/d11/mymodule/stats_word.py b/exercises/1901010161/d11/mymodule/stats_word.py new file mode 100644 index 000000000..f6abc1b21 --- /dev/null +++ b/exercises/1901010161/d11/mymodule/stats_word.py @@ -0,0 +1,35 @@ +import re # 调用正则表达式 +import collections +import jieba +count = int() + + +def stats_text_en(text, count): # 定义英语文本统计函数 + if type(text) == str: + m = re.sub(r'[^A-Za-z]', ' ', text) # 将text中任意非字母成分替换为空 + stri = m.split() # 切分英文单词,建立字符串 + return(collections.Counter(stri).most_common(count)) + else: + raise ValueError('type of argument is not string') + + +def stats_text_cn(text, count): # 定义中文文本统计函数 + if type(text) == str: + p = re.compile(r'[\u4e00-\u9fa5]') # 中文基本汉字(20902字)的编码范围是:\u4e00到\u9fa5 + res = re.findall(p, text) # 获取所有中文字符 + str1 = "".join(res) + str2 = jieba.lcut(str1) # 结巴分词 + text1 = [] + for i in str2: + if len(i) >= 2: + text1.append(i) + return(collections.Counter(text1).most_common(count)) + else: + raise ValueError('type of argument is not string') + + +def stats_text(text, count): # 定义文本统计函数 + if type(text) == str: + return(stats_text_en(text, count) + stats_text_cn(text, count)) # 输出合并英文和中文词频统计结果 + else: + raise ValueError('type of argument is not string') From e615e9fa96aeb57a755fcda309c9672dc75d1939 Mon Sep 17 00:00:00 2001 From: Zezhou-Sun <894101858@qq.com> Date: Sat, 9 Nov 2019 20:02:17 +0800 Subject: [PATCH 2/4] Update 00.py --- exercises/1901010161/d11/00.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/exercises/1901010161/d11/00.py b/exercises/1901010161/d11/00.py index 965cb9f6e..0ebb2a315 100644 --- a/exercises/1901010161/d11/00.py +++ b/exercises/1901010161/d11/00.py @@ -28,8 +28,6 @@ print(countlist_str) # Use getpass to enter the email address related information import getpass -sender = input('894101858@qq.com') ##'Enter the email address of sender:' -password = getpass.getpass('kdkrtqtbtazubdef') ##'Enter the password of the email from sender:' recipients = input('pythoncamp@163.com') ##'Enter the email address of the reciever:' # Leverage yagmail to send out emai import yagmail From e0ca191b94b96117c3331d6dc6739d6f6b756b8b Mon Sep 17 00:00:00 2001 From: Zezhou-Sun <894101858@qq.com> Date: Tue, 19 Nov 2019 21:01:58 +0800 Subject: [PATCH 3/4] day12 --- exercises/1901010161/d10/{00.py => 00} | 0 exercises/1901010161/d11/main | 12 ++++++ exercises/1901010161/d11/main.py | 38 +++++++++++++++---- exercises/1901010161/{d11 => d12}/00.py | 0 exercises/1901010161/d12/1111.code-workspace | 8 ++++ exercises/1901010161/d12/main.py | 31 +++++++++++++++ .../1901010161/d12/mymodule/stats_word.py | 35 +++++++++++++++++ 7 files changed, 117 insertions(+), 7 deletions(-) rename exercises/1901010161/d10/{00.py => 00} (100%) create mode 100644 exercises/1901010161/d11/main rename exercises/1901010161/{d11 => d12}/00.py (100%) create mode 100644 exercises/1901010161/d12/1111.code-workspace create mode 100644 exercises/1901010161/d12/main.py create mode 100644 exercises/1901010161/d12/mymodule/stats_word.py diff --git a/exercises/1901010161/d10/00.py b/exercises/1901010161/d10/00 similarity index 100% rename from exercises/1901010161/d10/00.py rename to exercises/1901010161/d10/00 diff --git a/exercises/1901010161/d11/main b/exercises/1901010161/d11/main new file mode 100644 index 000000000..4288af16f --- /dev/null +++ b/exercises/1901010161/d11/main @@ -0,0 +1,12 @@ +from mymodule import stats_word + +path = r'd:\用户目录\我的文档\GitHub\selfteaching-python-camp\exercises\1901010161\d11\mymodule\tang300.json' +with open(path, 'r', encoding='UTF-8') as f: # byte编码的类型名称是 UTF-8 + + read_date = f.read() + + +try: + print('出现频率最高的前20个词: \n', stats_word.stats_text_cn(read_date, 20)) +except ValueError: + print('ValueError:type of argument is not string!') diff --git a/exercises/1901010161/d11/main.py b/exercises/1901010161/d11/main.py index 4288af16f..0ebb2a315 100644 --- a/exercises/1901010161/d11/main.py +++ b/exercises/1901010161/d11/main.py @@ -1,12 +1,36 @@ +import requests +import getpass +import yagmail +from pyquery import PyQuery as py from mymodule import stats_word -path = r'd:\用户目录\我的文档\GitHub\selfteaching-python-camp\exercises\1901010161\d11\mymodule\tang300.json' -with open(path, 'r', encoding='UTF-8') as f: # byte编码的类型名称是 UTF-8 +reponse = requests.get('https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA') # 网页请求 +web_text = reponse.text # 保存更多网页文本数据 +document = py(web_text) +content = document('#js_content').text() +print('content=', content) - read_date = f.read() +w_list = stats_word.stats_text_cn(content, 100) +w_list = str(w_list) +print(w_list) +sender = input("请输入发件人邮箱:") +password = getpass.getpass("输入发件人邮箱授权码:") -try: - print('出现频率最高的前20个词: \n', stats_word.stats_text_cn(read_date, 20)) -except ValueError: - print('ValueError:type of argument is not string!') +yagmail.register(sender, password) + +yag = yagmail.SMTP(sender, password, host='smtp.qq.com') +yag.send('pythoncamp@163.com', '【1901010161】自学训练营学习2群DAY11 Zezhou-Sun', w_list) +print("发送成功") + +''' +countlist_str = ''.join(str(i) for i in countlist) +print(countlist_str) +# Use getpass to enter the email address related information +import getpass +recipients = input('pythoncamp@163.com') ##'Enter the email address of the reciever:' +# Leverage yagmail to send out emai +import yagmail +yag = yagmail.SMTP(user=sender, password=password, host='smtp.qq.com') +yag.send(recipients, '【1901010161】自学训练营学习2群DAY11 Zezhou-Sun', countlist_str) +''' diff --git a/exercises/1901010161/d11/00.py b/exercises/1901010161/d12/00.py similarity index 100% rename from exercises/1901010161/d11/00.py rename to exercises/1901010161/d12/00.py diff --git a/exercises/1901010161/d12/1111.code-workspace b/exercises/1901010161/d12/1111.code-workspace new file mode 100644 index 000000000..a4fe0a37c --- /dev/null +++ b/exercises/1901010161/d12/1111.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "D:\\用户目录\\我的文档\\GitHub\\selfteaching-python-camp\\exercises\\1901010161" + } + ], + "settings": {} +} \ No newline at end of file diff --git a/exercises/1901010161/d12/main.py b/exercises/1901010161/d12/main.py new file mode 100644 index 000000000..a784315c2 --- /dev/null +++ b/exercises/1901010161/d12/main.py @@ -0,0 +1,31 @@ +from mymodule import stats_word +from wxpy import Bot, Message, embed +from pyquery import PyQuery +import requests + +bot = Bot() # 初始化机器人,扫码登录 +my_friend = bot.friends().search('闫')[0] # 查找好友 +my_friend.send('分享任意微信文章给我') # 发生文本给好友 + +# 监听消息 +# 回复好友消息 +@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() + + +path = r'd:\用户目录\我的文档\GitHub\selfteaching-python-camp\exercises\1901010161\d11\mymodule\tang300.json' +with open(path, 'r', encoding='UTF-8') as f: # byte编码的类型名称是 UTF-8 + read_date = f.read() + + +try: + print('出现频率最高的前20个词: \n', stats_word.stats_text_cn(read_date, 20)) +except ValueError: + print('ValueError:type of argument is not string!') diff --git a/exercises/1901010161/d12/mymodule/stats_word.py b/exercises/1901010161/d12/mymodule/stats_word.py new file mode 100644 index 000000000..f6abc1b21 --- /dev/null +++ b/exercises/1901010161/d12/mymodule/stats_word.py @@ -0,0 +1,35 @@ +import re # 调用正则表达式 +import collections +import jieba +count = int() + + +def stats_text_en(text, count): # 定义英语文本统计函数 + if type(text) == str: + m = re.sub(r'[^A-Za-z]', ' ', text) # 将text中任意非字母成分替换为空 + stri = m.split() # 切分英文单词,建立字符串 + return(collections.Counter(stri).most_common(count)) + else: + raise ValueError('type of argument is not string') + + +def stats_text_cn(text, count): # 定义中文文本统计函数 + if type(text) == str: + p = re.compile(r'[\u4e00-\u9fa5]') # 中文基本汉字(20902字)的编码范围是:\u4e00到\u9fa5 + res = re.findall(p, text) # 获取所有中文字符 + str1 = "".join(res) + str2 = jieba.lcut(str1) # 结巴分词 + text1 = [] + for i in str2: + if len(i) >= 2: + text1.append(i) + return(collections.Counter(text1).most_common(count)) + else: + raise ValueError('type of argument is not string') + + +def stats_text(text, count): # 定义文本统计函数 + if type(text) == str: + return(stats_text_en(text, count) + stats_text_cn(text, count)) # 输出合并英文和中文词频统计结果 + else: + raise ValueError('type of argument is not string') From 0a17929cb780e1536a9fa36d9a1e70d43c755cd6 Mon Sep 17 00:00:00 2001 From: Zezhou-Sun <894101858@qq.com> Date: Tue, 19 Nov 2019 21:13:47 +0800 Subject: [PATCH 4/4] 11 --- exercises/1901010161/d11/00.py | 36 ++++++++++++++++++++++++++++++ exercises/1901010161/d11/main | 12 ---------- exercises/1901010161/d11/main.py | 38 ++++++-------------------------- 3 files changed, 43 insertions(+), 43 deletions(-) create mode 100644 exercises/1901010161/d11/00.py delete mode 100644 exercises/1901010161/d11/main diff --git a/exercises/1901010161/d11/00.py b/exercises/1901010161/d11/00.py new file mode 100644 index 000000000..0ebb2a315 --- /dev/null +++ b/exercises/1901010161/d11/00.py @@ -0,0 +1,36 @@ +import requests +import getpass +import yagmail +from pyquery import PyQuery as py +from mymodule import stats_word + +reponse = requests.get('https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA') # 网页请求 +web_text = reponse.text # 保存更多网页文本数据 +document = py(web_text) +content = document('#js_content').text() +print('content=', content) + +w_list = stats_word.stats_text_cn(content, 100) +w_list = str(w_list) +print(w_list) + +sender = input("请输入发件人邮箱:") +password = getpass.getpass("输入发件人邮箱授权码:") + +yagmail.register(sender, password) + +yag = yagmail.SMTP(sender, password, host='smtp.qq.com') +yag.send('pythoncamp@163.com', '【1901010161】自学训练营学习2群DAY11 Zezhou-Sun', w_list) +print("发送成功") + +''' +countlist_str = ''.join(str(i) for i in countlist) +print(countlist_str) +# Use getpass to enter the email address related information +import getpass +recipients = input('pythoncamp@163.com') ##'Enter the email address of the reciever:' +# Leverage yagmail to send out emai +import yagmail +yag = yagmail.SMTP(user=sender, password=password, host='smtp.qq.com') +yag.send(recipients, '【1901010161】自学训练营学习2群DAY11 Zezhou-Sun', countlist_str) +''' diff --git a/exercises/1901010161/d11/main b/exercises/1901010161/d11/main deleted file mode 100644 index 4288af16f..000000000 --- a/exercises/1901010161/d11/main +++ /dev/null @@ -1,12 +0,0 @@ -from mymodule import stats_word - -path = r'd:\用户目录\我的文档\GitHub\selfteaching-python-camp\exercises\1901010161\d11\mymodule\tang300.json' -with open(path, 'r', encoding='UTF-8') as f: # byte编码的类型名称是 UTF-8 - - read_date = f.read() - - -try: - print('出现频率最高的前20个词: \n', stats_word.stats_text_cn(read_date, 20)) -except ValueError: - print('ValueError:type of argument is not string!') diff --git a/exercises/1901010161/d11/main.py b/exercises/1901010161/d11/main.py index 0ebb2a315..4288af16f 100644 --- a/exercises/1901010161/d11/main.py +++ b/exercises/1901010161/d11/main.py @@ -1,36 +1,12 @@ -import requests -import getpass -import yagmail -from pyquery import PyQuery as py from mymodule import stats_word -reponse = requests.get('https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA') # 网页请求 -web_text = reponse.text # 保存更多网页文本数据 -document = py(web_text) -content = document('#js_content').text() -print('content=', content) +path = r'd:\用户目录\我的文档\GitHub\selfteaching-python-camp\exercises\1901010161\d11\mymodule\tang300.json' +with open(path, 'r', encoding='UTF-8') as f: # byte编码的类型名称是 UTF-8 -w_list = stats_word.stats_text_cn(content, 100) -w_list = str(w_list) -print(w_list) + read_date = f.read() -sender = input("请输入发件人邮箱:") -password = getpass.getpass("输入发件人邮箱授权码:") -yagmail.register(sender, password) - -yag = yagmail.SMTP(sender, password, host='smtp.qq.com') -yag.send('pythoncamp@163.com', '【1901010161】自学训练营学习2群DAY11 Zezhou-Sun', w_list) -print("发送成功") - -''' -countlist_str = ''.join(str(i) for i in countlist) -print(countlist_str) -# Use getpass to enter the email address related information -import getpass -recipients = input('pythoncamp@163.com') ##'Enter the email address of the reciever:' -# Leverage yagmail to send out emai -import yagmail -yag = yagmail.SMTP(user=sender, password=password, host='smtp.qq.com') -yag.send(recipients, '【1901010161】自学训练营学习2群DAY11 Zezhou-Sun', countlist_str) -''' +try: + print('出现频率最高的前20个词: \n', stats_word.stats_text_cn(read_date, 20)) +except ValueError: + print('ValueError:type of argument is not string!')