Skip to content
Merged

d12 #6184

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions exercises/1901010161/1001S02E03_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
File renamed without changes.
36 changes: 36 additions & 0 deletions exercises/1901010161/d11/00.py
Original file line number Diff line number Diff line change
@@ -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)
'''
8 changes: 8 additions & 0 deletions exercises/1901010161/d11/1111.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "D:\\用户目录\\我的文档\\GitHub\\selfteaching-python-camp\\exercises\\1901010161"
}
],
"settings": {}
}
12 changes: 12 additions & 0 deletions exercises/1901010161/d11/main.py
Original file line number Diff line number Diff line change
@@ -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!')
35 changes: 35 additions & 0 deletions exercises/1901010161/d11/mymodule/stats_word.py
Original file line number Diff line number Diff line change
@@ -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')
36 changes: 36 additions & 0 deletions exercises/1901010161/d12/00.py
Original file line number Diff line number Diff line change
@@ -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)
'''
8 changes: 8 additions & 0 deletions exercises/1901010161/d12/1111.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "D:\\用户目录\\我的文档\\GitHub\\selfteaching-python-camp\\exercises\\1901010161"
}
],
"settings": {}
}
31 changes: 31 additions & 0 deletions exercises/1901010161/d12/main.py
Original file line number Diff line number Diff line change
@@ -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!')
35 changes: 35 additions & 0 deletions exercises/1901010161/d12/mymodule/stats_word.py
Original file line number Diff line number Diff line change
@@ -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')