Skip to content

Commit 6a58782

Browse files
CoderWanFengheyWFeng
authored andcommitted
add receive_message()
1 parent c2e0449 commit 6a58782

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

PyOfficeRobot/api/chat.py

+22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from PyOfficeRobot.core.WeChatType import WeChat
22
from PyOfficeRobot.lib.CONST import ACT_TYPE
33
from PyOfficeRobot.lib.dec.act_dec import act_info
4+
import datetime
5+
import os
46

57
wx = WeChat()
68

@@ -40,3 +42,23 @@ def chat_by_keywords(who, keywords):
4042
wx.SendMsg(keywords[receive_msg]) # 向`who`发送消息
4143
except:
4244
pass
45+
46+
47+
def receive_message(who='文件传输助手', txt='userMessage.txt', output_path='./'):
48+
wx.GetSessionList() # 获取会话列表
49+
wx.ChatWith(who) # 打开`who`聊天窗口
50+
while True:
51+
friend_name, receive_msg = wx.GetAllMessage[-1][0], wx.GetAllMessage[-1][1] # 获取朋友的名字、发送的信息
52+
current_time = datetime.datetime.now()
53+
cut_line = '^^^----------^^^'
54+
print('--' * 88)
55+
with open(os.path.join(output_path, txt), 'a+') as output_file:
56+
output_file.write('\n')
57+
output_file.write(cut_line)
58+
output_file.write('\n')
59+
output_file.write(str(current_time))
60+
output_file.write('\n')
61+
output_file.write(str(friend_name))
62+
output_file.write('\n')
63+
output_file.write(str(receive_msg))
64+
output_file.write('\n')

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = PyOfficeRobot
3-
version = 0.0.10
3+
version = 0.0.11
44
description = pip install PyOfficeRobot
55
long_description = file: README.md
66
long_description_content_type = text/markdown

tests/test_file.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22

3-
from PyOfficeRobot.api.chat import chat_by_keyword
3+
from PyOfficeRobot.api.chat import *
44
from PyOfficeRobot.api.file import *
55

66
keywords = {
@@ -13,4 +13,7 @@ def test_send_file(self):
1313
send_file(who='文件传输助手', file=r'./test_files/0816.jpg')
1414

1515
def test_chat_by_keyword(self):
16-
chat_by_keyword(who='兆锋', keywords=keywords)
16+
chat_by_keywords(who='程序员晚枫', keywords=keywords)
17+
18+
def test_receive_message(self):
19+
receive_message(who='程序员晚枫')

0 commit comments

Comments
 (0)