9
9
from PIL import ImageDraw
10
10
from PIL import ImageFont
11
11
12
+ import pickle
13
+
14
+
12
15
common = Common () #这是个我自己封装的工具类
13
16
key = 'cc186c9881b94b42b886a6d634c63002'
14
17
key_jh = '777d35900bffe58af88f56069b12785c'
15
18
# 提取故事的第一天
16
- readBookStartDay = datetime .datetime (2019 , 2 , 19 )
19
+ readBookStartDay = datetime .datetime (2019 , 3 , 30 )
17
20
# 提取情话的第一天
18
21
qinghuaStartDay = datetime .datetime (2019 , 3 , 19 )
22
+ # 天气计算开始时间
23
+ weatherStartDay = datetime .datetime (2019 , 4 , 14 )
24
+ cityList = [ '九江' , '九江' , '九江' ,'九江' , '九江' , '九江' , '九江' ,'九江' , '九江' , '九江' , '九江' , '九江' ,'九江' , '九江' , '九江' , '九江' ,'九江' , '九江' , '九江' ];
19
25
class DataUtil ():
20
26
21
27
# 获取天气信息
22
28
def getWeatherData (self , cityname ):
29
+ today = datetime .datetime .now ()
30
+ dayCount = (today - weatherStartDay ).days
31
+ # cityname = cityList[dayCount]
23
32
# 阿凡达数据
24
33
url = ' http://api.avatardata.cn/Weather/Query?key=' + key + '&cityname=' + cityname
25
34
# 聚合数据
@@ -73,13 +82,14 @@ def parseInfo_jh(self, jsons):
73
82
textInfo = textInfo + 'by:小可爱的贴心秘书' + '\n '
74
83
return textInfo
75
84
85
+ # 睡前故事
76
86
def getBookInfo (self , filePath ):
77
87
radioList = [] #微信每次最多只能发送的字符是有限制的,我每25行发送一次信息
78
- tempInfo = '睡前故事:张嘉佳 - 《从你的全世界路过 》.\n \n '
88
+ tempInfo = '睡前故事:刘瑜 - 《送你一颗子弹 》.\n \n '
79
89
readFlag = False #是否读取
80
90
today = datetime .datetime .now ()
81
91
dayCount = (today - readBookStartDay ).days + 1
82
- for line in open (filePath ):
92
+ for line in open (filePath , encoding = 'utf-8' ):
83
93
if (line .find ('night.' + str (dayCount )) > - 1 ): # 开始读数据
84
94
readFlag = True
85
95
continue
@@ -98,6 +108,25 @@ def getBookInfo(self, filePath):
98
108
print (radioList )
99
109
return radioList
100
110
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
+ # 每日情话
101
130
def getQinghua (self , filePath ):
102
131
tempInfo = '晚安:\n '
103
132
readFlag = False # 是否读取
@@ -112,10 +141,11 @@ def getQinghua(self, filePath):
112
141
if readFlag :
113
142
tempInfo += line
114
143
144
+ tempInfo += '\n 爱你!\n '
115
145
print (tempInfo )
116
146
return tempInfo
117
147
118
-
148
+ # 每日美图
119
149
def getBingPhoto (self , index ):
120
150
# index 对应的是 必应 index天的壁纸
121
151
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):
149
179
150
180
msg_information = {}
151
181
if __name__ == '__main__' :
182
+
152
183
dataUtil = DataUtil ()
153
- # dataUtil.getWeatherData('九江' )
184
+ dataUtil .getDaily ( )
154
185
# 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')
157
189
# for line in open('送你一颗子弹.txt', encoding='utf-8'):
158
190
# print(line)
159
191
# b = line != ' \n'
@@ -174,9 +206,9 @@ def getBingPhoto(self, index):
174
206
# print(msg_information)
175
207
176
208
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)
181
213
182
214
0 commit comments