Skip to content

Commit ae7baf9

Browse files
author
zhaww
committed
更新添加每日一句任务
1 parent bc41aec commit ae7baf9

File tree

2 files changed

+54
-21
lines changed

2 files changed

+54
-21
lines changed

venv/Include/wechat/autoSendMessage.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,19 @@ def sendMessage(self, message, name):
9797
# 推送睡前故事
9898
def readStory(self):
9999
print('readStory do')
100-
stroy = dataUtil.getBookInfo('./从你的全世界路过.txt')
100+
# stroy = dataUtil.getBookInfo('./从你的全世界路过.txt')
101+
stroy = dataUtil.getBookInfo('./送你一颗子弹.txt')
101102
dataUtil.getBingPhoto('0')
102-
# wechat.sendMessage(stroy, 'filehelper')
103-
# itchat.send_image('./bing.jpg', 'filehelper')
104103
yfei = wechat.getFriend('乐多')
105104

106105
for txt in stroy:
107106
wechat.sendMessage(txt, yfei)
107+
# wechat.sendMessage(txt, 'filehelper')
108108

109-
# itchat.send_file('./Passing through your world.mp3', toUserName=yfei)
110109
itchat.send_image('./bing.jpg', toUserName=yfei)
110+
# itchat.send_image('./bing.jpg', 'filehelper')
111+
112+
# itchat.send_file('./Passing through your world.mp3', toUserName=yfei)
111113
# group2 = wechat.getRoom('( ̄(●●) ̄)')
112114
# wechat.sendMessage(stroy, group2)
113115

@@ -117,7 +119,6 @@ def dailyInfo(self):
117119
jiujiang = dataUtil.getWeatherData('九江')
118120
# wechat.sendMessage(jiujiang, 'filehelper')
119121
yfei = wechat.getFriend('乐多')
120-
121122
wechat.sendMessage(jiujiang, yfei)
122123
# group2 = wechat.getRoom('幸福一家人')
123124
# wechat.sendMessage(hangz, group2)
@@ -127,9 +128,9 @@ def dailyInfo(self):
127128
# qinghua
128129
def qinghua(self):
129130
print('qinghua do')
130-
qinghua = dataUtil.getQinghua('./qinghua.txt')
131+
dailyMessage = dataUtil.getDaily()
131132
yfei = wechat.getFriend('乐多')
132-
wechat.sendMessage(qinghua, yfei)
133+
wechat.sendMessage(dailyMessage, yfei)
133134

134135
# 闹钟
135136
def alarm(self):
@@ -192,9 +193,9 @@ def get_response(msg):
192193

193194
# 配置定时任务
194195
# 开启早间天气预报 定时任务
195-
schedule.every().day.at("7:20").do(wechat.dailyInfo)
196-
# 开启情话 定时任务
197-
schedule.every().day.at("23:00").do(wechat.qinghua)
196+
schedule.every().day.at("7:00").do(wechat.dailyInfo)
197+
# 开启每日一句 定时任务
198+
schedule.every().day.at("20:00").do(wechat.qinghua)
198199
# 开启睡前故事 定时任务
199200
schedule.every().day.at("21:30").do(wechat.readStory)
200201
while True:

venv/Include/wechat/chatUseData.py

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,26 @@
99
from PIL import ImageDraw
1010
from PIL import ImageFont
1111

12+
import pickle
13+
14+
1215
common = Common() #这是个我自己封装的工具类
1316
key = 'cc186c9881b94b42b886a6d634c63002'
1417
key_jh = '777d35900bffe58af88f56069b12785c'
1518
# 提取故事的第一天
16-
readBookStartDay = datetime.datetime(2019, 2, 19)
19+
readBookStartDay = datetime.datetime(2019, 3, 30)
1720
# 提取情话的第一天
1821
qinghuaStartDay = datetime.datetime(2019, 3, 19)
22+
# 天气计算开始时间
23+
weatherStartDay = datetime.datetime(2019, 4, 14)
24+
cityList = [ '九江', '九江', '九江','九江', '九江', '九江', '九江','九江', '九江', '九江', '九江', '九江','九江', '九江', '九江', '九江','九江', '九江', '九江'];
1925
class DataUtil():
2026

2127
# 获取天气信息
2228
def getWeatherData(self, cityname):
29+
today = datetime.datetime.now()
30+
dayCount = (today - weatherStartDay).days
31+
# cityname = cityList[dayCount]
2332
# 阿凡达数据
2433
url = ' http://api.avatardata.cn/Weather/Query?key=' + key + '&cityname=' + cityname
2534
# 聚合数据
@@ -73,13 +82,14 @@ def parseInfo_jh(self, jsons):
7382
textInfo = textInfo + 'by:小可爱的贴心秘书' + '\n'
7483
return textInfo
7584

85+
# 睡前故事
7686
def getBookInfo(self, filePath):
7787
radioList = [] #微信每次最多只能发送的字符是有限制的,我每25行发送一次信息
78-
tempInfo = '睡前故事:张嘉佳 - 《从你的全世界路过》.\n\n'
88+
tempInfo = '睡前故事:刘瑜 - 《送你一颗子弹》.\n\n'
7989
readFlag = False #是否读取
8090
today = datetime.datetime.now()
8191
dayCount = (today - readBookStartDay).days + 1
82-
for line in open(filePath):
92+
for line in open(filePath, encoding='utf-8'):
8393
if (line.find('night.' + str(dayCount)) > -1): # 开始读数据
8494
readFlag = True
8595
continue
@@ -98,6 +108,25 @@ def getBookInfo(self, filePath):
98108
print(radioList)
99109
return radioList
100110

111+
# 每日一句
112+
def getDaily(self):
113+
nowDay = datetime.datetime.now().strftime('%Y-%m-%d');
114+
tempInfo = '早安:\n'
115+
url = "http://open.iciba.com/dsapi/" # 官方提供的API
116+
results = common.get(url)
117+
resultsData = json.loads(results)
118+
content = resultsData['content']
119+
note = resultsData['note']
120+
translation = resultsData['translation']
121+
translation = translation.replace("小编的话", "多说一句")
122+
tempInfo += content + '\n'
123+
tempInfo += note + '\n\n'
124+
tempInfo += translation + '\n'
125+
tempInfo += '\n爱你!\n'
126+
print(tempInfo)
127+
return tempInfo
128+
129+
# 每日情话
101130
def getQinghua(self, filePath):
102131
tempInfo = '晚安:\n'
103132
readFlag = False # 是否读取
@@ -112,10 +141,11 @@ def getQinghua(self, filePath):
112141
if readFlag:
113142
tempInfo += line
114143

144+
tempInfo += '\n爱你!\n'
115145
print(tempInfo)
116146
return tempInfo
117147

118-
148+
# 每日美图
119149
def getBingPhoto(self, index):
120150
# index 对应的是 必应 index天的壁纸
121151
url = ' http://www.bing.com/HPImageArchive.aspx?format=js&idx=' + index + '&n=1&nc=1469612460690&pid=hp&video=1'
@@ -149,11 +179,13 @@ def getBingPhoto(self, index):
149179

150180
msg_information = {}
151181
if __name__ == '__main__':
182+
152183
dataUtil = DataUtil()
153-
# dataUtil.getWeatherData('九江')
184+
dataUtil.getDaily()
154185
# dataUtil.getBingPhoto('3')
155-
stroy = dataUtil.getBookInfo('./从你的全世界路过.txt')
156-
# # qinghua = dataUtil.getQinghua('./qinghua.txt')
186+
# stroy = dataUtil.getBookInfo('./送你一颗子弹.txt')
187+
188+
# qinghua = dataUtil.getQinghua('./qinghua.txt')
157189
# for line in open('送你一颗子弹.txt', encoding='utf-8'):
158190
# print(line)
159191
# b = line != ' \n'
@@ -174,9 +206,9 @@ def getBingPhoto(self, index):
174206
# print(msg_information)
175207

176208

177-
with open('./送你1颗子弹.txt',encoding='utf-8',mode = 'w') as f:
178-
for line in open('./送你一颗子弹.txt', encoding='utf-8'):
179-
if line != ' \n':
180-
f.writelines(line)
209+
# with open('./送你1颗子弹.txt',encoding='utf-8',mode = 'w') as f:
210+
# for line in open('./送你一颗子弹.txt', encoding='utf-8'):
211+
# if line != ' \n':
212+
# f.writelines(line)
181213

182214

0 commit comments

Comments
 (0)