Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a30cbd2
day1
superjmm Aug 29, 2019
0e66fa6
Create 1001S02E02_hello_python.py
superjmm Aug 30, 2019
9297b3a
Merge pull request #1 from selfteaching/master
superjmm Aug 30, 2019
b827264
Create 1001S02E03_calculator.py
superjmm Aug 31, 2019
71115a6
Merge branch 'master' of https://github.com/superjmm/selfteaching-pyt…
superjmm Aug 31, 2019
4e19deb
1901100296 自学训练营学习20群 DAY4
superjmm Sep 1, 2019
b5e7247
Merge branch 'master' into master
liujiayi0042 Sep 2, 2019
27b661d
Update 1001S02E04_control_flow.py
superjmm Sep 3, 2019
9876316
1901100296 自学训练营学习20群 DAY5
superjmm Sep 3, 2019
9991898
Merge branch 'master' of https://github.com/superjmm/selfteaching-pyt…
superjmm Sep 3, 2019
98e212a
Merge branch 'master' into master
liujiayi0042 Sep 4, 2019
64bd6f8
1901100296 自学训练营学习20群 DAY6
superjmm Sep 5, 2019
693c0e1
1901100296 自学训练营学习20群 DAY7
superjmm Sep 5, 2019
0833752
1901100296 自学训练营学习20群 DAY7
superjmm Sep 5, 2019
18eba13
Merge branch 'master' into master
liujiayi0042 Sep 5, 2019
6cba983
1901100296 自学训练营学习20群 DAY8
superjmm Sep 6, 2019
a1df650
Merge branch 'master' of https://github.com/superjmm/selfteaching-pyt…
superjmm Sep 6, 2019
26eb108
Merge branch 'master' into master
liujiayi0042 Sep 8, 2019
1f0711d
1901100296 自学训练营学习20群 DAY9
superjmm Sep 8, 2019
d5f177f
Merge branch 'master' of https://github.com/superjmm/selfteaching-pyt…
superjmm Sep 8, 2019
eb682f4
1901100296 自学训练营学习20群 DAY9
superjmm Sep 8, 2019
03628db
1901100296 自学训练营学习20群 DAY10
superjmm Sep 9, 2019
c1287e5
1901100296 自学训练营学习20群 DAY11
superjmm Sep 10, 2019
93c2617
Merge branch 'master' into master
liujiayi0042 Sep 11, 2019
2c6d1cb
1901100296 自学训练营学习20群 DAY12
superjmm Sep 13, 2019
feb4142
Merge branch 'master' of https://github.com/superjmm/selfteaching-pyt…
superjmm Sep 13, 2019
7ca7145
1901100296 自学训练营学习20群 DAY13
superjmm Sep 17, 2019
1c11376
Merge branch 'master' into master
liujiayi0042 Sep 18, 2019
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
36 changes: 30 additions & 6 deletions exercises/1901100296/d11/main.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
from mymodule import stats_word
import getpass
import yagmail
import requests
import logging
from pyquery import PyQuery

def postemail(content,title):
# 获取网页内容
def get_content(url):
# 请求网页返回内容
response = requests.get(url)
# 提取微信公众号正⽂
document = PyQuery(response.text)
content = document('#js_content').text()
return content
# 发邮件
def post_email(content,title):
sender = input('输⼊发件⼈邮箱:')
password = getpass.getpass('输⼊发件⼈邮箱密码(可复制粘贴):')
recipients = input('输⼊收件⼈邮箱:')
yag = yagmail.SMTP(sender,password)
# yag = yagmail.SMTP(sender,password)
# yag = yagmail.SMTP(sender,password,'smtp.163.com')
yag = yagmail.SMTP(sender,password,'smtp.qq.com')
yag.send(recipients,title,content)

def main():
logging.basicConfig(format='file:%(filename)s|line:%(lineno)d|message:%(message)s',level=logging.DEBUG)
try:
url='https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA'
content = stats_word.stats_text_cn(get_content(url),100)
# content = '测试!!'
# print('统计结果:',content)
# logging.info('%s %s',type(content),str(content))
post_email(content,'1901100296 自学训练营学习20群DAY11')
logging.info('已发送,请注意查收!')
except Exception as e:
logging.exception(e)

if __name__ == '__main__':
url='https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA'
content = stats_word.stats_text_cn(stats_word.getcontent(url),100)
# print('统计结果:',content)
postemail(content,'统计结果')
main()

17 changes: 4 additions & 13 deletions exercises/1901100296/d11/mymodule/stats_word.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
import collections
import jieba
import requests
import yagmail
import json
from pyquery import PyQuery

# 获取网页内容
def getcontent(url):
# 请求网页返回内容
response = requests.get(url)
# 提取微信公众号正⽂
document = PyQuery(response.text)
content = document('#js_content').text()
return content

import json

# 封装统计汉字词频的函数
def stats_text_cn(text,count):
Expand All @@ -28,6 +16,9 @@ def stats_text_cn(text,count):
words.append(word)
# 使用标准库的Counter统计词和词频数,返回前count位的数据
cnt_words = collections.Counter(words).most_common(count)

# res_words = str(cnt_words)

res_words=''
for r in cnt_words:
a,b = r
Expand Down
56 changes: 19 additions & 37 deletions exercises/1901100296/d12/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,27 @@
import getpass
import yagmail
from wxpy import *
# import wxpy


def postemail(content,title):
sender = input('输⼊发件⼈邮箱:')
password = getpass.getpass('输⼊发件⼈邮箱密码(可复制粘贴):')
recipients = input('输⼊收件⼈邮箱:')
yag = yagmail.SMTP(sender,password)
yag.send(recipients,title,content)
logging.basicConfig(format='file:%(filename)s|line:%(lineno)d|message:%(message:%(message)s',level=logging.DEBUG)
def main():
# 初始化机器人,扫码登录
bot = Bot()
# 找到好友和群聊
my_friends = bot.friends()
# family_group = bot.groups()

# 监听好友信息,自动响应分享类型的消息
@bot.register(my_friends,SHARING)
def handler(msg):
try:
logging.info('sharing url=%s',msg.url)
result = stats_word.stats_text_cn(stats_word.getcontent(msg.url),100)
msg.reply(str(result))
except Exception as e:
logging.exception(e)
embed()
if __name__ == '__main__':
main()

# 初始化机器人,扫码登录
bot = Bot()
# 找到好友和群聊
my_friend = bot.friends().search('老运')[0]
# family_group = bot.groups().search('家人')[0]

# 发送消息给好友
my_friend.send('hello!')
# my_friend.send_image('1.jpg')
# 自动响应消息
# 打印消息
@bot.register()
def just_print(msg):
print(msg)
# 取得消息内容的URL
@bot.register()
def get_url(msg):
if msg.type == SHARING:
content = stats_word.stats_text_cn(stats_word.getcontent(msg.url),100)
# 回复好友消息
@bot.register(my_friend)
def reply_my_friend():
return '处理结果:{}'.format(content)

embed()
# if __name__ == '__main__':
# url='https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA'
# content = stats_word.stats_text_cn(stats_word.getcontent(url),100)
# print('统计结果:',content)
# postemail(content,'统计结果')

11 changes: 3 additions & 8 deletions exercises/1901100296/d12/mymodule/stats_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ def stats_text_cn(text,count):
words.append(word)
# 使用标准库的Counter统计词和词频数,返回前count位的数据
cnt_words = collections.Counter(words).most_common(count)
res_words=''
for r in cnt_words:
a,b = r
w = a + ':' +str(b)
# print(w)
res_words = res_words + '\n' + w

return res_words

return cnt_words

Binary file added exercises/1901100296/d13/SimHei.ttf
Binary file not shown.
52 changes: 52 additions & 0 deletions exercises/1901100296/d13/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from mymodule import stats_word
import getpass
import yagmail
from wxpy import *
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
from os import path

logging.basicConfig(format='file:%(filename)s|line:%(lineno)d|message:%(message:%(message)s',level=logging.DEBUG)

file_path = path.join(path.dirname(path.abspath(__file__)),'SimHei.ttf')

# 将统计结果画成条形图并返回条形图的保存路径
def stats_barplot(list_data):
zhfont1 = matplotlib.font_manager.FontProperties(fname=file_path)

words = [x[0] for x in list_data ]
frequence = [x[1] for x in list_data]

fig,ax = plt.subplots()
ax.barh(words,frequence)
ylabels = ax.get_yticklabels()
plt.setp(ylabels,FontProperties=zhfont1)
ax.set_xlabel('词频',FontProperties=zhfont1)
ax.set_ylabel('词语',FontProperties=zhfont1)
ax.set_title('文章中出现次数在前10的词语',FontProperties=zhfont1)
png_path = path.join(path.dirname(path.abspath(__file__)),'stats_words_barplot.png')
fig.savefig(png_path,transparen=False,dpi=80,bbox_inches="tight")
# plt.show()
return png_path

def main():
# 初始化机器人,扫码登录
bot = Bot()
# 找到好友和群聊
my_friends = bot.friends()
# family_group = bot.groups()

# 监听好友信息,自动响应分享类型的消息
@bot.register(my_friends,SHARING)
def handler(msg):
try:
logging.info('sharing url=%s',msg.url)
msg.reply(stats_barplot(result))
except Exception as e:
logging.exception(e)
embed()

if __name__ == '__main__':
main()

31 changes: 31 additions & 0 deletions exercises/1901100296/d13/mymodule/stats_word.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import collections
import jieba
import requests
import yagmail
import json
from pyquery import PyQuery

# 获取网页内容
def getcontent(url):
# 请求网页返回内容
response = requests.get(url)
# 提取微信公众号正⽂
document = PyQuery(response.text)
content = document('#js_content').text()
return content


# 封装统计汉字词频的函数
def stats_text_cn(text,count):
if type(text)!=str:
raise ValueError('输入类型 %s,参数必须是 str 类型'%type(text))
# 使用jieba分词
seg_words = jieba.cut(text)
# 长度大于等于2的词
words = []
for word in seg_words:
if len(word) >= 2:
words.append(word)
# 使用标准库的Counter统计词和词频数,返回前count位的数据
cnt_words = collections.Counter(words).most_common(count)
return cnt_words