1
|
|
|
# -*- coding: utf-8 -*- |
2
|
10 |
|
from __future__ import absolute_import, unicode_literals |
3
|
10 |
|
import datetime |
4
|
|
|
|
5
|
10 |
|
import six |
6
|
|
|
|
7
|
10 |
|
from wechatpy.client.api.base import BaseWeChatAPI |
8
|
|
|
|
9
|
|
|
|
10
|
10 |
|
class WeChatDataCube(BaseWeChatAPI): |
11
|
|
|
|
12
|
10 |
|
API_BASE_URL = 'https://api.weixin.qq.com/datacube/' |
13
|
|
|
|
14
|
10 |
|
@classmethod |
15
|
|
|
def _to_date_str(cls, date): |
16
|
10 |
|
if isinstance(date, (datetime.datetime, datetime.date)): |
17
|
10 |
|
return date.strftime('%Y-%m-%d') |
18
|
10 |
|
elif isinstance(date, six.string_types): |
19
|
10 |
|
return date |
20
|
|
|
else: |
21
|
|
|
raise ValueError('Can not convert %s type to str', type(date)) |
22
|
|
|
|
23
|
10 |
|
def get_user_summary(self, begin_date, end_date): |
24
|
|
|
""" |
25
|
|
|
获取用户增减数据 |
26
|
|
|
详情请参考 |
27
|
|
|
http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html |
28
|
|
|
|
29
|
|
|
:param begin_date: 起始日期 |
30
|
|
|
:param end_date: 结束日期 |
31
|
|
|
:return: 统计数据列表 |
32
|
|
|
""" |
33
|
10 |
|
res = self._post( |
34
|
|
|
'getusersummary', |
35
|
|
|
data={ |
36
|
|
|
'begin_date': self._to_date_str(begin_date), |
37
|
|
|
'end_date': self._to_date_str(end_date) |
38
|
|
|
} |
39
|
|
|
) |
40
|
10 |
|
return res['list'] |
41
|
|
|
|
42
|
10 |
|
def get_user_cumulate(self, begin_date, end_date): |
43
|
|
|
""" |
44
|
|
|
获取累计用户数据 |
45
|
|
|
详情请参考 |
46
|
|
|
http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html |
47
|
|
|
|
48
|
|
|
:param begin_date: 起始日期 |
49
|
|
|
:param end_date: 结束日期 |
50
|
|
|
:return: 统计数据列表 |
51
|
|
|
""" |
52
|
10 |
|
res = self._post( |
53
|
|
|
'getusercumulate', |
54
|
|
|
data={ |
55
|
|
|
'begin_date': self._to_date_str(begin_date), |
56
|
|
|
'end_date': self._to_date_str(end_date) |
57
|
|
|
}, |
58
|
|
|
result_processor=lambda x: x['list'] |
59
|
|
|
) |
60
|
10 |
|
return res |
61
|
|
|
|
62
|
10 |
|
def get_interface_summary(self, begin_date, end_date): |
63
|
|
|
""" |
64
|
|
|
获取接口分析数据 |
65
|
|
|
详情请参考 |
66
|
|
|
http://mp.weixin.qq.com/wiki/8/30ed81ae38cf4f977194bf1a5db73668.html |
67
|
|
|
|
68
|
|
|
:param begin_date: 起始日期 |
69
|
|
|
:param end_date: 结束日期 |
70
|
|
|
:return: 统计数据列表 |
71
|
|
|
""" |
72
|
10 |
|
res = self._post( |
73
|
|
|
'getinterfacesummary', |
74
|
|
|
data={ |
75
|
|
|
'begin_date': self._to_date_str(begin_date), |
76
|
|
|
'end_date': self._to_date_str(end_date) |
77
|
|
|
}, |
78
|
|
|
result_processor=lambda x: x['list'] |
79
|
|
|
) |
80
|
10 |
|
return res |
81
|
|
|
|
82
|
10 |
|
def get_interface_summary_hour(self, begin_date, end_date): |
83
|
|
|
""" |
84
|
|
|
获取接口分析分时数据 |
85
|
|
|
详情请参考 |
86
|
|
|
http://mp.weixin.qq.com/wiki/8/30ed81ae38cf4f977194bf1a5db73668.html |
87
|
|
|
|
88
|
|
|
:param begin_date: 起始日期 |
89
|
|
|
:param end_date: 结束日期 |
90
|
|
|
:return: 统计数据列表 |
91
|
|
|
""" |
92
|
10 |
|
res = self._post( |
93
|
|
|
'getinterfacesummaryhour', |
94
|
|
|
data={ |
95
|
|
|
'begin_date': self._to_date_str(begin_date), |
96
|
|
|
'end_date': self._to_date_str(end_date) |
97
|
|
|
}, |
98
|
|
|
result_processor=lambda x: x['list'] |
99
|
|
|
) |
100
|
10 |
|
return res |
101
|
|
|
|
102
|
10 |
|
def get_article_summary(self, begin_date, end_date): |
103
|
|
|
""" |
104
|
|
|
获取图文群发每日数据 |
105
|
|
|
详情请参考 |
106
|
|
|
http://mp.weixin.qq.com/wiki/8/c0453610fb5131d1fcb17b4e87c82050.html |
107
|
|
|
|
108
|
|
|
:param begin_date: 起始日期 |
109
|
|
|
:param end_date: 结束日期 |
110
|
|
|
:return: 统计数据列表 |
111
|
|
|
""" |
112
|
10 |
|
res = self._post( |
113
|
|
|
'getarticlesummary', |
114
|
|
|
data={ |
115
|
|
|
'begin_date': self._to_date_str(begin_date), |
116
|
|
|
'end_date': self._to_date_str(end_date) |
117
|
|
|
}, |
118
|
|
|
result_processor=lambda x: x['list'] |
119
|
|
|
) |
120
|
10 |
|
return res |
121
|
|
|
|
122
|
10 |
|
def get_article_total(self, begin_date, end_date): |
123
|
|
|
""" |
124
|
|
|
获取图文群发总数据 |
125
|
|
|
详情请参考 |
126
|
|
|
http://mp.weixin.qq.com/wiki/8/c0453610fb5131d1fcb17b4e87c82050.html |
127
|
|
|
|
128
|
|
|
:param begin_date: 起始日期 |
129
|
|
|
:param end_date: 结束日期 |
130
|
|
|
:return: 统计数据列表 |
131
|
|
|
""" |
132
|
10 |
|
res = self._post( |
133
|
|
|
'getarticletotal', |
134
|
|
|
data={ |
135
|
|
|
'begin_date': self._to_date_str(begin_date), |
136
|
|
|
'end_date': self._to_date_str(end_date) |
137
|
|
|
}, |
138
|
|
|
result_processor=lambda x: x['list'] |
139
|
|
|
) |
140
|
10 |
|
return res |
141
|
|
|
|
142
|
10 |
|
def get_user_read(self, begin_date, end_date): |
143
|
|
|
""" |
144
|
|
|
获取图文统计数据 |
145
|
|
|
详情请参考 |
146
|
|
|
http://mp.weixin.qq.com/wiki/8/c0453610fb5131d1fcb17b4e87c82050.html |
147
|
|
|
|
148
|
|
|
:param begin_date: 起始日期 |
149
|
|
|
:param end_date: 结束日期 |
150
|
|
|
:return: 统计数据列表 |
151
|
|
|
""" |
152
|
10 |
|
res = self._post( |
153
|
|
|
'getuserread', |
154
|
|
|
data={ |
155
|
|
|
'begin_date': self._to_date_str(begin_date), |
156
|
|
|
'end_date': self._to_date_str(end_date) |
157
|
|
|
}, |
158
|
|
|
result_processor=lambda x: x['list'] |
159
|
|
|
) |
160
|
10 |
|
return res |
161
|
|
|
|
162
|
10 |
|
def get_user_read_hour(self, begin_date, end_date): |
163
|
|
|
""" |
164
|
|
|
获取图文分时统计数据 |
165
|
|
|
详情请参考 |
166
|
|
|
http://mp.weixin.qq.com/wiki/8/c0453610fb5131d1fcb17b4e87c82050.html |
167
|
|
|
|
168
|
|
|
:param begin_date: 起始日期 |
169
|
|
|
:param end_date: 结束日期 |
170
|
|
|
:return: 统计数据列表 |
171
|
|
|
""" |
172
|
10 |
|
res = self._post( |
173
|
|
|
'getuserreadhour', |
174
|
|
|
data={ |
175
|
|
|
'begin_date': self._to_date_str(begin_date), |
176
|
|
|
'end_date': self._to_date_str(end_date) |
177
|
|
|
}, |
178
|
|
|
result_processor=lambda x: x['list'] |
179
|
|
|
) |
180
|
10 |
|
return res |
181
|
|
|
|
182
|
10 |
|
def get_user_share(self, begin_date, end_date): |
183
|
|
|
""" |
184
|
|
|
获取图文分享转发数据 |
185
|
|
|
详情请参考 |
186
|
|
|
http://mp.weixin.qq.com/wiki/8/c0453610fb5131d1fcb17b4e87c82050.html |
187
|
|
|
|
188
|
|
|
:param begin_date: 起始日期 |
189
|
|
|
:param end_date: 结束日期 |
190
|
|
|
:return: 统计数据列表 |
191
|
|
|
""" |
192
|
10 |
|
res = self._post( |
193
|
|
|
'getusershare', |
194
|
|
|
data={ |
195
|
|
|
'begin_date': self._to_date_str(begin_date), |
196
|
|
|
'end_date': self._to_date_str(end_date) |
197
|
|
|
}, |
198
|
|
|
result_processor=lambda x: x['list'] |
199
|
|
|
) |
200
|
10 |
|
return res |
201
|
|
|
|
202
|
10 |
|
def get_user_share_hour(self, begin_date, end_date): |
203
|
|
|
""" |
204
|
|
|
获取图文分享转发分时数据 |
205
|
|
|
详情请参考 |
206
|
|
|
http://mp.weixin.qq.com/wiki/8/c0453610fb5131d1fcb17b4e87c82050.html |
207
|
|
|
|
208
|
|
|
:param begin_date: 起始日期 |
209
|
|
|
:param end_date: 结束日期 |
210
|
|
|
:return: 统计数据列表 |
211
|
|
|
""" |
212
|
10 |
|
res = self._post( |
213
|
|
|
'getusersharehour', |
214
|
|
|
data={ |
215
|
|
|
'begin_date': self._to_date_str(begin_date), |
216
|
|
|
'end_date': self._to_date_str(end_date) |
217
|
|
|
}, |
218
|
|
|
result_processor=lambda x: x['list'] |
219
|
|
|
) |
220
|
10 |
|
return res |
221
|
|
|
|
222
|
10 |
|
def get_upstream_msg(self, begin_date, end_date): |
223
|
|
|
""" |
224
|
|
|
获取消息发送概况数据 |
225
|
|
|
详情请参考 |
226
|
|
|
http://mp.weixin.qq.com/wiki/12/32d42ad542f2e4fc8a8aa60e1bce9838.html |
227
|
|
|
|
228
|
|
|
:param begin_date: 起始日期 |
229
|
|
|
:param end_date: 结束日期 |
230
|
|
|
:return: 统计数据列表 |
231
|
|
|
""" |
232
|
10 |
|
res = self._post( |
233
|
|
|
'getupstreammsg', |
234
|
|
|
data={ |
235
|
|
|
'begin_date': self._to_date_str(begin_date), |
236
|
|
|
'end_date': self._to_date_str(end_date) |
237
|
|
|
}, |
238
|
|
|
result_processor=lambda x: x['list'] |
239
|
|
|
) |
240
|
10 |
|
return res |
241
|
|
|
|
242
|
10 |
|
def get_upstream_msg_hour(self, begin_date, end_date): |
243
|
|
|
""" |
244
|
|
|
获取消息发送分时数据 |
245
|
|
|
详情请参考 |
246
|
|
|
http://mp.weixin.qq.com/wiki/12/32d42ad542f2e4fc8a8aa60e1bce9838.html |
247
|
|
|
|
248
|
|
|
:param begin_date: 起始日期 |
249
|
|
|
:param end_date: 结束日期 |
250
|
|
|
:return: 统计数据列表 |
251
|
|
|
""" |
252
|
10 |
|
res = self._post( |
253
|
|
|
'getupstreammsghour', |
254
|
|
|
data={ |
255
|
|
|
'begin_date': self._to_date_str(begin_date), |
256
|
|
|
'end_date': self._to_date_str(end_date) |
257
|
|
|
}, |
258
|
|
|
result_processor=lambda x: x['list'] |
259
|
|
|
) |
260
|
10 |
|
return res |
261
|
|
|
|
262
|
10 |
|
def get_upstream_msg_week(self, begin_date, end_date): |
263
|
|
|
""" |
264
|
|
|
获取消息发送周数据 |
265
|
|
|
详情请参考 |
266
|
|
|
http://mp.weixin.qq.com/wiki/12/32d42ad542f2e4fc8a8aa60e1bce9838.html |
267
|
|
|
|
268
|
|
|
:param begin_date: 起始日期 |
269
|
|
|
:param end_date: 结束日期 |
270
|
|
|
:return: 统计数据列表 |
271
|
|
|
""" |
272
|
10 |
|
res = self._post( |
273
|
|
|
'getupstreammsgweek', |
274
|
|
|
data={ |
275
|
|
|
'begin_date': self._to_date_str(begin_date), |
276
|
|
|
'end_date': self._to_date_str(end_date) |
277
|
|
|
}, |
278
|
|
|
result_processor=lambda x: x['list'] |
279
|
|
|
) |
280
|
10 |
|
return res |
281
|
|
|
|
282
|
10 |
|
def get_upstream_msg_month(self, begin_date, end_date): |
283
|
|
|
""" |
284
|
|
|
获取消息发送月数据 |
285
|
|
|
详情请参考 |
286
|
|
|
http://mp.weixin.qq.com/wiki/12/32d42ad542f2e4fc8a8aa60e1bce9838.html |
287
|
|
|
|
288
|
|
|
:param begin_date: 起始日期 |
289
|
|
|
:param end_date: 结束日期 |
290
|
|
|
:return: 统计数据列表 |
291
|
|
|
""" |
292
|
10 |
|
res = self._post( |
293
|
|
|
'getupstreammsgmonth', |
294
|
|
|
data={ |
295
|
|
|
'begin_date': self._to_date_str(begin_date), |
296
|
|
|
'end_date': self._to_date_str(end_date) |
297
|
|
|
}, |
298
|
|
|
result_processor=lambda x: x['list'] |
299
|
|
|
) |
300
|
10 |
|
return res |
301
|
|
|
|
302
|
10 |
|
def get_upstream_msg_dist(self, begin_date, end_date): |
303
|
|
|
""" |
304
|
|
|
获取消息发送分布数据 |
305
|
|
|
详情请参考 |
306
|
|
|
http://mp.weixin.qq.com/wiki/12/32d42ad542f2e4fc8a8aa60e1bce9838.html |
307
|
|
|
|
308
|
|
|
:param begin_date: 起始日期 |
309
|
|
|
:param end_date: 结束日期 |
310
|
|
|
:return: 统计数据列表 |
311
|
|
|
""" |
312
|
10 |
|
res = self._post( |
313
|
|
|
'getupstreammsgdist', |
314
|
|
|
data={ |
315
|
|
|
'begin_date': self._to_date_str(begin_date), |
316
|
|
|
'end_date': self._to_date_str(end_date) |
317
|
|
|
}, |
318
|
|
|
result_processor=lambda x: x['list'] |
319
|
|
|
) |
320
|
10 |
|
return res |
321
|
|
|
|
322
|
10 |
|
def get_upstream_msg_dist_week(self, begin_date, end_date): |
323
|
|
|
""" |
324
|
|
|
获取消息发送分布数据 |
325
|
|
|
详情请参考 |
326
|
|
|
http://mp.weixin.qq.com/wiki/12/32d42ad542f2e4fc8a8aa60e1bce9838.html |
327
|
|
|
|
328
|
|
|
:param begin_date: 起始日期 |
329
|
|
|
:param end_date: 结束日期 |
330
|
|
|
:return: 统计数据列表 |
331
|
|
|
""" |
332
|
10 |
|
res = self._post( |
333
|
|
|
'getupstreammsgdistweek', |
334
|
|
|
data={ |
335
|
|
|
'begin_date': self._to_date_str(begin_date), |
336
|
|
|
'end_date': self._to_date_str(end_date) |
337
|
|
|
}, |
338
|
|
|
result_processor=lambda x: x['list'] |
339
|
|
|
) |
340
|
10 |
|
return res |
341
|
|
|
|
342
|
10 |
|
def get_upstream_msg_dist_month(self, begin_date, end_date): |
343
|
|
|
""" |
344
|
|
|
获取消息发送分布数据 |
345
|
|
|
详情请参考 |
346
|
|
|
http://mp.weixin.qq.com/wiki/12/32d42ad542f2e4fc8a8aa60e1bce9838.html |
347
|
|
|
|
348
|
|
|
:param begin_date: 起始日期 |
349
|
|
|
:param end_date: 结束日期 |
350
|
|
|
:return: 统计数据列表 |
351
|
|
|
""" |
352
|
10 |
|
res = self._post( |
353
|
|
|
'getupstreammsgdistmonth', |
354
|
|
|
data={ |
355
|
|
|
'begin_date': self._to_date_str(begin_date), |
356
|
|
|
'end_date': self._to_date_str(end_date) |
357
|
|
|
}, |
358
|
|
|
result_processor=lambda x: x['list'] |
359
|
|
|
) |
360
|
|
|
return res |
361
|
|
|
|