Skip to content
Merged
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
Binary file added exercises/1901080018/QR.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions exercises/1901080018/d12/mymodule/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from wxpy import *
bot = Bot()
my_friend = bot.friends().search("波罗",sex=MALE,city='广州')[0]
my_friend.send('我找到你了')
@bot.register(chats =None,msg_types = 'Sharing',except_self = True)
def auto_reply(msg):
import requests
from pyquery import PyQuery
import stats_word
response = requests.get('https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA')
document = PyQuery(response.text)
content = document('#js_content').text()
list1 = stats_word.stats_text(content,100)
str1 = "".join([str(i) for i in list1])
return str1
embed()
32 changes: 32 additions & 0 deletions exercises/1901080018/d12/mymodule/stats_word.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@


import jieba
import re
import collections
def stats_text_en(en,count):
if isinstance(en,str):
d = {}
t1 = re.sub(u"([^\u0041-\u005a\u0061-\u007a\'])"," ",en)
t2 = t1.split()
d=collections.Counter(t2).most_common(count)
return d
else:
raise ValueError ("输入的不是文本,请重新输入")
def stats_text_cn(cn,count):
if isinstance(cn,str):
d={}
t2=[]
t1=re.sub(u"([^\u4e00-\u9fa5])","",cn)
seg_list = jieba.cut(t1,cut_all=False)
for i in seg_list:
if len(i) >= 2:
t2.append(i)
d=collections.Counter(t2).most_common(count)
return d
else:
raise ValueError("输入的不是文本,请重新输入")
def stats_text(ec,count): #创建stats_text函数
if isinstance(ec,str): #如果ec是字符串,则运行下面一行的代码。
return stats_text_cn(ec,count) + stats_text_en(ec,count) #返回值为stats_text_cn(ec)和stats_text_en(ec)的结果。
else: #否则提示错误:输入的不是文本。。。。。。
raise ValueError ("输入的不是文本,请重新输入")
Loading