当前位置: 首页>>代码示例>>Python>>正文


Python MailSnake.listMemberActivity方法代码示例

本文整理汇总了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
开发者ID:spulec,项目名称:mailchimp_rapleaf,代码行数:32,代码来源:connect.py


注:本文中的mailsnake.MailSnake.listMemberActivity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。