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


Python MailSnake.listStaticSegmentAdd方法代码示例

本文整理汇总了Python中mailsnake.MailSnake.listStaticSegmentAdd方法的典型用法代码示例。如果您正苦于以下问题:Python MailSnake.listStaticSegmentAdd方法的具体用法?Python MailSnake.listStaticSegmentAdd怎么用?Python MailSnake.listStaticSegmentAdd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mailsnake.MailSnake的用法示例。


在下文中一共展示了MailSnake.listStaticSegmentAdd方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_main_list_segment

# 需要导入模块: from mailsnake import MailSnake [as 别名]
# 或者: from mailsnake.MailSnake import listStaticSegmentAdd [as 别名]
    def update_main_list_segment(self):
        segment_name = 'Ticketholders'
        segment_id = None

        tix = Ticket.query.filter_by(paid=True).join(User).\
            group_by(User).with_entities(User).order_by(User.id)
        email_addresses = [ticket.email for ticket in tix]

        ms = MailSnake(app.config['MAILCHIMP_KEY'])
        segments = ms.listStaticSegments(id=app.config['MAILCHIMP_LIST'])

        for segment in segments:
            if segment['name'] == segment_name:
                segment_id = segment['id']

        if segment_id is None:
            segment_id = ms.listStaticSegmentAdd(id=app.config['MAILCHIMP_LIST'], name=segment_name)

        results = ms.listStaticSegmentMembersAdd(id=app.config['MAILCHIMP_LIST'],
                                                 seg_id=segment_id, batch=email_addresses)
        app.logger.info("Segment updated. Success: %s, failed: %s", results['success'],
                        len(results['errors']))
开发者ID:bfirsh,项目名称:Website,代码行数:24,代码来源:utils.py

示例2: handle_noargs

# 需要导入模块: from mailsnake import MailSnake [as 别名]
# 或者: from mailsnake.MailSnake import listStaticSegmentAdd [as 别名]
	def handle_noargs(self, **options):
		try:
			ms = MailSnake('f92abfa01e0a9cecc885186de4e37106-us7')
			self.stdout.write('connected to mailchimp')
		except:
			raise CommandError("Can't connect to MailChimp")

		#check if segment already exists
		seg_id = None
		if options['all']:
			seg_name = 'Designers'
		else:
			seg_name = 'Week ' + datetime.today().strftime('%W-%Y')

		for segment in ms.listStaticSegments(id='ed61191f4e'):
			if segment['name'] == seg_name:
				seg_id = segment['id']
				self.stdout.write('Segment already exists with id ' + str(seg_id))

		#otherwise create segment	
		try:
			if seg_id == None:
				seg_id = ms.listStaticSegmentAdd(id='ed61191f4e', name=seg_name)
				self.stdout.write('created segment with id: ' + str(seg_id))
		except:
			raise CommandError("Error creating segment")

		#query all or only current designs
		if options['all']:
			designs = Design.objects.all()
		else:
			designs = Design.objects.filter(created__gt=datetime.now(timezone('Europe/London')) - timedelta(days=14))
		try: 
			for design in designs:
				ms.listStaticSegmentMembersAdd(id='ed61191f4e', seg_id=seg_id,batch=[design.designer.email])
				self.stdout.write('added: ' + design.designer.email)
		except:
			raise CommandError("Error adding users")
		self.stdout.write('done.')
开发者ID:jmorrice,项目名称:garmsby-snippets,代码行数:41,代码来源:exportdesigners.py

示例3: handle

# 需要导入模块: from mailsnake import MailSnake [as 别名]
# 或者: from mailsnake.MailSnake import listStaticSegmentAdd [as 别名]
	def handle(self, *args, **options):
		for design_name in args:
			#check if design with that name exists
			try:
				design_name = design_name.replace('_',' ')
				design = Design.objects.get(name=design_name)
			except:
				raise CommandError("Design with that name doesn't exist.")

			#connect to mailchimp	
			try:
				ms = MailSnake('f92abfa01e0a9cecc885186de4e37106-us7')
				self.stdout.write('connected to mailchimp')
			except:
				raise CommandError("Can't connect to MailChimp")

			#check if segment already exists
			seg_id = None
			seg_name = 'Design Followers: ' + design.name
			for segment in ms.listStaticSegments(id='ed61191f4e'):
				if segment['name'] == seg_name:
					seg_id = segment['id']
					self.stdout.write('Segment already exists with id ' + str(seg_id))

			#otherwise create segment	
			try:
				if seg_id == None:
					seg_id = ms.listStaticSegmentAdd(id='ed61191f4e', name=seg_name)
					self.stdout.write('created segment with id: ' + str(seg_id))
			except:
				raise CommandError("Error creating segment")

			#add users who liked the design to mailchimp segment
			likes = Like.objects.filter(design=design.id)
			self.stdout.write(design.name + ' has ' + str(likes.count()) + ' likes in total. Adding users to mailchimp segment...')

			try:
				for like in likes:
					if like.user.email:
						ms.listStaticSegmentMembersAdd(id='ed61191f4e', seg_id=seg_id,batch=[like.user.email])
						self.stdout.write('added: ' + like.user.email)
					else:
						self.stdout.write('no email for: ' + like.user.first_name + ' ' + like.user.last_name)
			except:
				raise CommandError("Error adding users")

			#add users who requested a shop notification to mailchimp segment
			alerts = ReadyNotification.objects.filter(design=design.id)
			self.stdout.write(str(alerts.count()) + ' notifications were requested for ' + design.name + ' in total. Adding users to mailchimp segment...')

			try:
				for alert in alerts:
					if alert.user.email:
						ms.listStaticSegmentMembersAdd(id='ed61191f4e', seg_id=seg_id,batch=[alert.user.email])
						self.stdout.write('added: ' + alert.user.email)
					else:
						self.stdout.write('no email for: ' + alert.user.first_name + ' ' + alert.user.last_name)
			except:
				raise CommandError("Error adding users")

			self.stdout.write('done.')
开发者ID:jmorrice,项目名称:garmsby-snippets,代码行数:63,代码来源:exportlikes.py


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