Skip to content

Commit

Permalink
refactor: 更新 WeChatDataCube (#697)
Browse files Browse the repository at this point in the history
Co-authored-by: yaoqiankun <yaoqiankun@datarc.cn>
  • Loading branch information
yqkcn and yaoqiankun committed Mar 15, 2022
1 parent f268b48 commit b1e7cc2
Showing 1 changed file with 36 additions and 35 deletions.
71 changes: 36 additions & 35 deletions wechatpy/client/api/datacube.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

import datetime
from operator import itemgetter

from wechatpy.client.api.base import BaseWeChatAPI

Expand All @@ -11,7 +12,7 @@ class WeChatDataCube(BaseWeChatAPI):

@classmethod
def _to_date_str(cls, date):
if isinstance(date, (datetime.datetime, datetime.date)):
if isinstance(date, datetime.date):
return date.strftime("%Y-%m-%d")
elif isinstance(date, str):
return date
Expand All @@ -22,7 +23,7 @@ def get_user_summary(self, begin_date, end_date):
"""
获取用户增减数据
详情请参考
http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html
https://developers.weixin.qq.com/doc/offiaccount/Analytics/User_Analysis_Data_Interface.html
:param begin_date: 起始日期
:param end_date: 结束日期
Expand All @@ -41,7 +42,7 @@ def get_user_cumulate(self, begin_date, end_date):
"""
获取累计用户数据
详情请参考
http://mp.weixin.qq.com/wiki/3/ecfed6e1a0a03b5f35e5efac98e864b7.html
https://developers.weixin.qq.com/doc/offiaccount/Analytics/User_Analysis_Data_Interface.html
:param begin_date: 起始日期
:param end_date: 结束日期
Expand All @@ -53,15 +54,15 @@ def get_user_cumulate(self, begin_date, end_date):
"begin_date": self._to_date_str(begin_date),
"end_date": self._to_date_str(end_date),
},
result_processor=lambda x: x["list"],
result_processor=itemgetter("list"),
)
return res

def get_interface_summary(self, begin_date, end_date):
"""
获取接口分析数据
详情请参考
http://mp.weixin.qq.com/wiki/8/30ed81ae38cf4f977194bf1a5db73668.html
https://developers.weixin.qq.com/doc/offiaccount/Analytics/Analytics_API.html
:param begin_date: 起始日期
:param end_date: 结束日期
Expand All @@ -73,15 +74,15 @@ def get_interface_summary(self, begin_date, end_date):
"begin_date": self._to_date_str(begin_date),
"end_date": self._to_date_str(end_date),
},
result_processor=lambda x: x["list"],
result_processor=itemgetter("list"),
)
return res

def get_interface_summary_hour(self, begin_date, end_date):
"""
获取接口分析分时数据
详情请参考
http://mp.weixin.qq.com/wiki/8/30ed81ae38cf4f977194bf1a5db73668.html
https://developers.weixin.qq.com/doc/offiaccount/Analytics/Analytics_API.html
:param begin_date: 起始日期
:param end_date: 结束日期
Expand All @@ -93,15 +94,15 @@ def get_interface_summary_hour(self, begin_date, end_date):
"begin_date": self._to_date_str(begin_date),
"end_date": self._to_date_str(end_date),
},
result_processor=lambda x: x["list"],
result_processor=itemgetter("list"),
)
return res

def get_article_summary(self, begin_date, end_date):
"""
获取图文群发每日数据
详情请参考
http://mp.weixin.qq.com/wiki/8/c0453610fb5131d1fcb17b4e87c82050.html
https://developers.weixin.qq.com/doc/offiaccount/Analytics/Graphic_Analysis_Data_Interface.html
:param begin_date: 起始日期
:param end_date: 结束日期
Expand All @@ -113,15 +114,15 @@ def get_article_summary(self, begin_date, end_date):
"begin_date": self._to_date_str(begin_date),
"end_date": self._to_date_str(end_date),
},
result_processor=lambda x: x["list"],
result_processor=itemgetter("list"),
)
return res

def get_article_total(self, begin_date, end_date):
"""
获取图文群发总数据
详情请参考
http://mp.weixin.qq.com/wiki/8/c0453610fb5131d1fcb17b4e87c82050.html
https://developers.weixin.qq.com/doc/offiaccount/Analytics/Graphic_Analysis_Data_Interface.html
:param begin_date: 起始日期
:param end_date: 结束日期
Expand All @@ -133,15 +134,15 @@ def get_article_total(self, begin_date, end_date):
"begin_date": self._to_date_str(begin_date),
"end_date": self._to_date_str(end_date),
},
result_processor=lambda x: x["list"],
result_processor=itemgetter("list"),
)
return res

def get_user_read(self, begin_date, end_date):
"""
获取图文统计数据
详情请参考
http://mp.weixin.qq.com/wiki/8/c0453610fb5131d1fcb17b4e87c82050.html
https://developers.weixin.qq.com/doc/offiaccount/Analytics/Graphic_Analysis_Data_Interface.html
:param begin_date: 起始日期
:param end_date: 结束日期
Expand All @@ -153,15 +154,15 @@ def get_user_read(self, begin_date, end_date):
"begin_date": self._to_date_str(begin_date),
"end_date": self._to_date_str(end_date),
},
result_processor=lambda x: x["list"],
result_processor=itemgetter("list"),
)
return res

def get_user_read_hour(self, begin_date, end_date):
"""
获取图文分时统计数据
详情请参考
http://mp.weixin.qq.com/wiki/8/c0453610fb5131d1fcb17b4e87c82050.html
https://developers.weixin.qq.com/doc/offiaccount/Analytics/Graphic_Analysis_Data_Interface.html
:param begin_date: 起始日期
:param end_date: 结束日期
Expand All @@ -173,15 +174,15 @@ def get_user_read_hour(self, begin_date, end_date):
"begin_date": self._to_date_str(begin_date),
"end_date": self._to_date_str(end_date),
},
result_processor=lambda x: x["list"],
result_processor=itemgetter("list"),
)
return res

def get_user_share(self, begin_date, end_date):
"""
获取图文分享转发数据
详情请参考
http://mp.weixin.qq.com/wiki/8/c0453610fb5131d1fcb17b4e87c82050.html
https://developers.weixin.qq.com/doc/offiaccount/Analytics/Graphic_Analysis_Data_Interface.html
:param begin_date: 起始日期
:param end_date: 结束日期
Expand All @@ -193,15 +194,15 @@ def get_user_share(self, begin_date, end_date):
"begin_date": self._to_date_str(begin_date),
"end_date": self._to_date_str(end_date),
},
result_processor=lambda x: x["list"],
result_processor=itemgetter("list"),
)
return res

def get_user_share_hour(self, begin_date, end_date):
"""
获取图文分享转发分时数据
详情请参考
http://mp.weixin.qq.com/wiki/8/c0453610fb5131d1fcb17b4e87c82050.html
https://developers.weixin.qq.com/doc/offiaccount/Analytics/Graphic_Analysis_Data_Interface.html
:param begin_date: 起始日期
:param end_date: 结束日期
Expand All @@ -213,15 +214,15 @@ def get_user_share_hour(self, begin_date, end_date):
"begin_date": self._to_date_str(begin_date),
"end_date": self._to_date_str(end_date),
},
result_processor=lambda x: x["list"],
result_processor=itemgetter("list"),
)
return res

def get_upstream_msg(self, begin_date, end_date):
"""
获取消息发送概况数据
详情请参考
http://mp.weixin.qq.com/wiki/12/32d42ad542f2e4fc8a8aa60e1bce9838.html
https://developers.weixin.qq.com/doc/offiaccount/Analytics/Message_analysis_data_interface.html
:param begin_date: 起始日期
:param end_date: 结束日期
Expand All @@ -233,15 +234,15 @@ def get_upstream_msg(self, begin_date, end_date):
"begin_date": self._to_date_str(begin_date),
"end_date": self._to_date_str(end_date),
},
result_processor=lambda x: x["list"],
result_processor=itemgetter("list"),
)
return res

def get_upstream_msg_hour(self, begin_date, end_date):
"""
获取消息发送分时数据
详情请参考
http://mp.weixin.qq.com/wiki/12/32d42ad542f2e4fc8a8aa60e1bce9838.html
https://developers.weixin.qq.com/doc/offiaccount/Analytics/Message_analysis_data_interface.html
:param begin_date: 起始日期
:param end_date: 结束日期
Expand All @@ -253,15 +254,15 @@ def get_upstream_msg_hour(self, begin_date, end_date):
"begin_date": self._to_date_str(begin_date),
"end_date": self._to_date_str(end_date),
},
result_processor=lambda x: x["list"],
result_processor=itemgetter("list"),
)
return res

def get_upstream_msg_week(self, begin_date, end_date):
"""
获取消息发送周数据
详情请参考
http://mp.weixin.qq.com/wiki/12/32d42ad542f2e4fc8a8aa60e1bce9838.html
https://developers.weixin.qq.com/doc/offiaccount/Analytics/Message_analysis_data_interface.html
:param begin_date: 起始日期
:param end_date: 结束日期
Expand All @@ -273,7 +274,7 @@ def get_upstream_msg_week(self, begin_date, end_date):
"begin_date": self._to_date_str(begin_date),
"end_date": self._to_date_str(end_date),
},
result_processor=lambda x: x["list"],
result_processor=itemgetter("list"),
)
return res

Expand All @@ -293,15 +294,15 @@ def get_upstream_msg_month(self, begin_date, end_date):
"begin_date": self._to_date_str(begin_date),
"end_date": self._to_date_str(end_date),
},
result_processor=lambda x: x["list"],
result_processor=itemgetter("list"),
)
return res

def get_upstream_msg_dist(self, begin_date, end_date):
"""
获取消息发送分布数据
详情请参考
http://mp.weixin.qq.com/wiki/12/32d42ad542f2e4fc8a8aa60e1bce9838.html
https://developers.weixin.qq.com/doc/offiaccount/Analytics/Message_analysis_data_interface.html
:param begin_date: 起始日期
:param end_date: 结束日期
Expand All @@ -313,15 +314,15 @@ def get_upstream_msg_dist(self, begin_date, end_date):
"begin_date": self._to_date_str(begin_date),
"end_date": self._to_date_str(end_date),
},
result_processor=lambda x: x["list"],
result_processor=itemgetter("list"),
)
return res

def get_upstream_msg_dist_week(self, begin_date, end_date):
"""
获取消息发送分布数据
获取消息发送分布周数据
详情请参考
http://mp.weixin.qq.com/wiki/12/32d42ad542f2e4fc8a8aa60e1bce9838.html
https://developers.weixin.qq.com/doc/offiaccount/Analytics/Message_analysis_data_interface.html
:param begin_date: 起始日期
:param end_date: 结束日期
Expand All @@ -333,15 +334,15 @@ def get_upstream_msg_dist_week(self, begin_date, end_date):
"begin_date": self._to_date_str(begin_date),
"end_date": self._to_date_str(end_date),
},
result_processor=lambda x: x["list"],
result_processor=itemgetter("list"),
)
return res

def get_upstream_msg_dist_month(self, begin_date, end_date):
"""
获取消息发送分布数据
获取消息发送分布月数据
详情请参考
http://mp.weixin.qq.com/wiki/12/32d42ad542f2e4fc8a8aa60e1bce9838.html
https://developers.weixin.qq.com/doc/offiaccount/Analytics/Message_analysis_data_interface.html
:param begin_date: 起始日期
:param end_date: 结束日期
Expand All @@ -353,6 +354,6 @@ def get_upstream_msg_dist_month(self, begin_date, end_date):
"begin_date": self._to_date_str(begin_date),
"end_date": self._to_date_str(end_date),
},
result_processor=lambda x: x["list"],
result_processor=itemgetter("list"),
)
return res

0 comments on commit b1e7cc2

Please sign in to comment.