本文整理匯總了Python中mailsnake.MailSnake.listMemberActivity方法的典型用法代碼示例。如果您正苦於以下問題:Python MailSnake.listMemberActivity方法的具體用法?Python MailSnake.listMemberActivity怎麽用?Python MailSnake.listMemberActivity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mailsnake.MailSnake
的用法示例。
在下文中一共展示了MailSnake.listMemberActivity方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from mailsnake import MailSnake [as 別名]
# 或者: from mailsnake.MailSnake import listMemberActivity [as 別名]
def main(mailchimp_key, list_id, rapleaf_key):
thirty_days_ago = datetime.datetime.now() - datetime.timedelta(days=30)
ms = MailSnake(mailchimp_key)
rapleaf = RapleafApi.RapleafApi(rapleaf_key)
members = ms.listMembers(id=list_id, limit=1500)['data']
active_members = []
for member in members:
member_activity = ms.listMemberActivity(id=list_id, email_address=member['email'])
actions = [action for action in member_activity['data'][0] if action['action'] == 'open']
if actions:
last_action = actions[0]
last_event = datetime.datetime.strptime(last_action['timestamp'], "%Y-%m-%d %H:%M:%S")
if last_event > thirty_days_ago:
active_members.append(member['email'])
age_map = defaultdict(int)
for active_member in active_members:
try:
response = rapleaf.query_by_email(active_member)
age = response.get("age")
age_map[age] += 1
# for k, v in response.iteritems():
# print '%s = %s' % (k, v)
except Exception as e:
print e
for x, y in age_map.iteritems():
print x, y