def send_feed_mail(): pub_feeds = EmailFeedData.objects(is_send=False) for pub_feed in pub_feeds: email = pub_feed['email'] now = datetime.datetime.now() email_data = get_email_data(pub_feed) if not email_data: continue partner_resume = get_partner_resume(email) email_data.update(partner_resume) subject = email_data['subject'] message = render_to_string('reco_feed_email.html', email_data) email_send_info = email_data['email_send_info'] receive_email = get_receive_email(email) result = asyn_bat_mail( receive_email, subject, message, ) if result.get('status') == 'success': EmailFeedData.objects(email=email, is_send=False).update( set__is_send=True, ) email_send_info.lastSendDate = now email_send_info.save() print '%s send email success' % email else: print '%s send email error, result %s' % (email, result)
def add_email_data(self, feed_oid, resume_oids): if not resume_oids: return False feed = Feed2.objects(id=feed_oid)[0] email = feed.username pub_admin = self.request.user.username email_feed = EmailFeedData.objects( feed=feed_oid, is_send=False, ).first() if email_feed: EmailFeedData.objects( feed=feed_oid, is_send=False, ).update( set__pub_admin=pub_admin, add_to_set__resumes=resume_oids, ) else: email_feed = EmailFeedData( email=email, pub_admin=pub_admin, feed=feed_oid, resumes=resume_oids, ) email_feed.save() return True
def get_feed_data(send_user): username = send_user.user.username weixin_openid = send_user.openid user_pub_feeds = EmailFeedData.objects( email=username, is_send=False, ).select_related() total_num = 0 keyword_list = [] feed_id = None for pub_feed in user_pub_feeds: feed_id = pub_feed.feed.id feed = Feed2.objects(id=feed_id, deleted=False).first() if not feed: continue resumes_count = len(pub_feed.resumes) total_num += resumes_count keywords = feed.title if feed.title else feed.keywords if total_num > 1 or len(user_pub_feeds) > 1: keywords = '{0}({1})'.format( keywords, resumes_count ) keyword_list.append(keywords.replace(u',', ',')) keyword_list = ', '.join(keyword_list).split(',') if len(keyword_list) > 3: keyword_list[3] = '...' keywords = ','.join(keyword_list[:4]) feed_data = {} feed_data['openid'] = weixin_openid feed_data['username'] = username feed_data['reco_num'] = 0 feed_data['feed_id'] = str(feed_id) feed_data['title'] = keywords feed_data['reco_num'] = total_num feed_data['display_time'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M") return feed_data
def send_feed_msg(): need_send_email = EmailFeedData.objects( is_send=False, ).distinct('email') weixin_users = WeixinUser.objects.filter( user__username__in=need_send_email ) for send_user in weixin_users: feed_data = get_feed_data(send_user) feed_id = feed_data.get('feed_id') title = feed_data['title'] reco_num = feed_data['reco_num'] display_time = feed_data['display_time'] send_data = WeixinService.get_feed_notify_msg_tpl() send_data['first']['value'] = "聘宝刚刚为您推荐了{0}封简历,优质候选人不能等,请尽快查阅简历".format(feed_data['reco_num']) send_data['keyword1']['value'] = title send_data['keyword2']['value'] = reco_num send_data['keyword3']['value'] = display_time send_data['remark']['value'] = "小宝提示:手机上每个职位定制只能浏览最多5封简历哦,请返回PC上查看全部的简历推荐." urls = WeixinService.get_recommand_url().split('?from=') url = '{0}{1}/?from={2}'.format(urls[0], feed_id, urls[1]) if reco_num == 0: send_data['first']['value'] = "小宝遗憾的通知您,以下职位暂时没有合适的人才匹配:", send_data['remark']['value'] = "不要气馁!小宝秘籍在此:你可以尝试修改定制内容,可能会有惊喜哦!" url = WeixinService.get_customize_url() ret = WxUtils.send_tpl_msg( openid=feed_data.get('openid'), tpl_id=WeixinService.get_template_msg_id(), data=send_data, url=url ) if ret.get('errcode') == 0: print '%s,(openid:%s) send weixin msg success' % (send_user.user.username, feed_data.get('openid')) else: print '%s,(openid:%s) send weixin msg error' % (send_user.user.username, feed_data.get('openid'))
def convert2pub_data(feed): username = feed.username feed_oid = feed.id feed_results = FeedResult.objects( feed=feed_oid, calc_time__gte=CONVERT_CACU_TIME, published=True, ) if not feed_results: return False FeedCacheUtils.add_feed_id_update_cache(feed_oid) pub_admin = '*****@*****.**' resumes = [fr.resume.id for fr in feed_results] email_feed = EmailFeedData.objects( feed=feed_oid, is_send=False, ).first() if email_feed: EmailFeedData.objects( feed=feed_oid, is_send=False, ).update( set__pub_admin=pub_admin, add_to_set__resumes=resumes, ) else: email_feed = EmailFeedData( email=username, pub_admin=pub_admin, feed=feed_oid, resumes=resumes, ) email_feed.save()
def get_email_data(pub_feed): after_tomorrow = get_tomommow() + datetime.timedelta(days=1) username = pub_feed.email last_send_info = EmailSendInfo.objects(username=username).first() if last_send_info: send_frequency = last_send_info.sendFrequency last_send_date = last_send_info.lastSendDate need_send = ( send_frequency and last_send_date + datetime.timedelta(days=send_frequency) <= after_tomorrow ) else: user = User.objects.filter(username=username)[0] last_send_info = EmailSendInfo( user=user.id, username=username, ) need_send = True if not need_send: return False user_pub_feeds = EmailFeedData.objects( email=username, is_send=False, ).select_related() if not user_pub_feeds: return False feed_info_list = [] total_num = 0 keyword_list = [] for pub_feed in user_pub_feeds: feed_id = pub_feed.feed.id feed = Feed2.objects(id=feed_id, deleted=False).first() if not feed: continue keywords = feed.title if feed.title else feed.keywords keyword_list.append(keywords.replace(u',', ',')) resume_num = len(pub_feed.resumes) feed.feed_resumes = get_display_resumes(feed_id, pub_feed.resumes) feed.feed_result_num = resume_num feed.token = get_email_token(username, feed_id) total_num += resume_num feed_info_list.append(feed) keyword_list = ','.join(keyword_list).split(',') if len(keyword_list) > 5: keyword_list[4] = '...' keywords = ','.join(keyword_list[:5]) subject = u'聘宝为你推荐人才-%s' % keywords return { 'username': username, 'subject': subject, 'feed_info_list': feed_info_list, 'total_num': total_num, 'email_send_info': last_send_info, }