Example #1
0
    def update_today_cache(cls):
        update_feed_id_list = cache.get(cls.update_cache_key, [])
        today = get_today()
        tomorrow = get_tomommow()

        has_update_feed_list = []

        for feed_id in update_feed_id_list:
            feed_oid = get_oid(feed_id)
            today_cache_key = feed_id + '_today_cache'
            today_cache_value = cache.get(today_cache_key, [])

            feed_results = FeedResult.objects(
                feed=feed_oid,
                display_time__gte=today,
                display_time__lt=tomorrow,
            )
            resume_ids = [str(fr.resume.id) for fr in feed_results]
            if resume_ids:
                today_cache_value = list(
                    set(today_cache_value) | set(resume_ids))
                cache.set(today_cache_key, today_cache_value, timeout=0)
                has_update_feed_list.append(feed_id)

        not_update_feed_list = list(
            set(update_feed_id_list) - set(has_update_feed_list))
        cache.set(cls.update_cache_key, not_update_feed_list, timeout=0)
Example #2
0
    def get_query_cond(self):
        tomorrow = get_tomommow()
        min_calc_time = tomorrow + datetime.timedelta(days=-30)
        query_meta = {
            'cached': {
                'is_recommended': True,
                'published': {
                    '$ne': True
                },
                'calc_time__gt': min_calc_time,
            },
            'user': {
                'published': True,
                'display_time__lt': tomorrow,
                'is_recommended': True,
            },
            'tomorrow': {
                'display_time__gte': tomorrow,
                'published': True,
                'is_recommended': True,
            },
            'shield': {
                'is_recommended': False,
                'calc_time__gt': min_calc_time,
            },
            'search_result': {},
        }

        view = self.request.GET.get('view', 'cached')
        query_cond = query_meta.get(view, {})
        query_cond = self.get_query_read_status(query_cond)
        query_cond = self.get_query_manual(query_cond)
        query_cond = self.get_query_calc_time(query_cond)
        return query_cond
def main():
    today = get_today()
    tomorrow = get_tomommow()

    expire_feeds = Feed2.objects(
        feed_expire_time__gte=today,
        feed_expire_time__lt=tomorrow,
        feed_type=1,
    )

    for feed in expire_feeds:
        if is_deleted_feed(feed):
            continue

        email = feed.username
        subject = get_email_subject(feed)
        message = render_to_string(
            'email-template/activate_tips.html',
            {'feed': feed}
        )

        result = asyn_bat_mail(
            email,
            subject,
            message,
        )
        if result.get('status') == 'success':
            print '%s send email success' % email
        else:
            print '%s send email error, result %s' % (email, result)
Example #4
0
    def get_feed_list(self, feed_id):
        feed_id = get_oid(feed_id)

        if not feed_id:
            return []

        page = get_int(self.request.GET.get('start', '0'))
        if page < 0:
            page = 0

        query_cond = self.get_query_cond()
        query_cond.update({'feed': feed_id})

        feed_result_list = FeedResult.objects(
            resume_source__ne='talent_partner',
            **query_cond).only(*self.only_fields).skip(
                self.page_count * page).limit(self.page_count).order_by(
                    *self.get_sort_cond()).select_related()

        feed_result_dict_list = []
        for f in feed_result_list:
            try:
                work_years = f.resume.get_work_years()
                feed_dict = mongo_to_dict(f, [])
                feed_result_dict_list.append(feed_dict)
                feed_dict['resume']['work_years'] = work_years
            except AttributeError:
                # 处理由于删除重复简历,导致的推荐结果缺失问题
                django_log.error('resume not exists %s' % f.resume.id)
                continue

        feed_query_count = FeedResult.objects(**query_cond).count()

        tomorrow = get_tomommow()
        total_count = 13 * FeedResult.objects(feed=feed_id).count()
        total_recommend_count = FeedResult.objects(
            feed=feed_id,
            published=True,
            is_recommended=True,
            display_time__lt=tomorrow,
        ).count()

        newest_recommend_count = FeedResult.objects(
            feed=feed_id,
            user_read_status__ne='read',
            published=True,
        ).count()

        return {
            'start': page,
            'next_start': page + 1 if feed_result_dict_list else -1,
            'data': feed_result_dict_list,
            'total_recommend_count': total_recommend_count,
            'total_count': total_count,
            'newest_recommend_count': newest_recommend_count,
            'feed_query_count': feed_query_count,
        }
def add_update_cache(feed):
    tomorrow = get_tomommow()
    today = get_today()
    feed_id = feed.id

    feed_results = FeedResult.objects(
        feed=feed_id,
        display_time__gte=today,
        display_time__lt=tomorrow,
    )
    resume_sids = [str(fr.resume.id) for fr in feed_results]
    FeedCacheUtils.add_update_cache(feed_id, resume_sids)
def add_update_cache(feed):
    tomorrow = get_tomommow()
    today = get_today()
    feed_id = feed.id

    feed_results = FeedResult.objects(
        feed=feed_id,
        display_time__gte=today,
        display_time__lt=tomorrow,
    )
    resume_sids = [str(fr.resume.id) for fr in feed_results]
    FeedCacheUtils.add_update_cache(feed_id, resume_sids)
Example #7
0
 def get_query_cond(self):
     tomorrow = get_tomommow()
     default_query_cond = {
         'display_time__lt': tomorrow,
         'published': True,
         'is_recommended': True,
     }
     query_cond = self.get_query_read_status(default_query_cond)
     query_cond = self.get_query_send(query_cond)
     query_cond = self.get_query_advance(query_cond)
     query_cond = self.query_extend_match(query_cond)
     query_cond = self.query_title_match(query_cond)
     query_cond = self.query_reco_time(query_cond)
     return query_cond
Example #8
0
    def convert_display_time(self, display_time_str):
        display_time = str2datetime(display_time_str)

        if not display_time:
            default_display_time = get_tomommow()
            return default_display_time

        # 展示时间只需要精确到天
        # 同一天的推荐结果需要按job_related排序
        display_time = datetime.datetime(
            display_time.year,
            display_time.month,
            display_time.day,
        )
        return display_time
Example #9
0
    def get_query_calc_time(self, query_cond):
        if not query_cond.get('calc_time__gt'):
            return query_cond

        calc_time_str = self.request.GET.get('calc_time')
        if not calc_time_str:
            return query_cond

        calc_time = str2datetime(calc_time_str)
        invalid_time = datetime.datetime(1990, 01, 01)

        tomorrow = get_tomommow()
        min_calc_time = tomorrow + datetime.timedelta(days=-15)

        if calc_time == invalid_time:
            calc_time = min_calc_time
        query_cond['calc_time__gt'] = calc_time
        return query_cond
Example #10
0
    def add_pub_data(self, feed_oid, resume_oids, display_time):
        if not resume_oids:
            return False

        today = get_today()
        tomorrow = get_tomommow()

        feed = Feed2.objects(id=feed_oid)[0]
        email = feed.username
        pub_admin = self.request.user.username

        pub_feed = PubFeedData.objects(
            feed=feed_oid,
            pub_time__gte=today,
            pub_time__lt=tomorrow,
        ).first()
        if pub_feed:
            if display_time == tomorrow:
                update_kwargs = {
                    'set__display_time': tomorrow,
                }
            else:
                update_kwargs = {}

            PubFeedData.objects(
                feed=feed_oid,
                pub_time__gte=today,
                pub_time__lt=tomorrow,
            ).update(set__pub_admin=pub_admin,
                     add_to_set__resumes=resume_oids,
                     **update_kwargs)
        else:
            pub_feed = PubFeedData(
                email=email,
                pub_admin=pub_admin,
                feed=feed_oid,
                resumes=resume_oids,
                pub_time=datetime.datetime.now(),
                display_time=display_time,
            )
        pub_feed.save()
        return True
Example #11
0
def main():
    old_feed_results = FeedResult.objects(
        published=True,
        display_time=None,
    ).order_by('-calc_time')

    today = get_today()
    tomorrow = get_tomommow()

    caculate_time = today + datetime.timedelta(hours=14)

    for feed_result in old_feed_results:
        calc_time = feed_result.calc_time
        if calc_time < caculate_time:
            feed_result.display_time = today
        else:
            feed_result.display_time = tomorrow
        feed_result.user_read_status = get_read_status(feed_result)
        feed_result.save()
        print feed_result.id, calc_time, feed_result.user_read_status, feed_result.display_time
def main():
    old_feed_results = FeedResult.objects(
        published=True,
        display_time=None,
    ).order_by('-calc_time')

    today = get_today()
    tomorrow = get_tomommow()

    caculate_time = today + datetime.timedelta(hours=14)

    for feed_result in old_feed_results:
        calc_time = feed_result.calc_time
        if calc_time < caculate_time:
            feed_result.display_time = today
        else:
            feed_result.display_time = tomorrow
        feed_result.user_read_status = get_read_status(feed_result)
        feed_result.save()
        print feed_result.id, calc_time, feed_result.user_read_status, feed_result.display_time
Example #13
0
 def get_today_expire_sec(cls):
     now = datetime.datetime.now()
     tomorrow = get_tomommow()
     expire_time = tomorrow - now
     expire_sec = expire_time.total_seconds()
     return expire_sec
Example #14
0
 def feed_expire_status(self, feed):
     today = get_tomommow()
     return True if (feed.feed_expire_time and feed.feed_expire_time < today
                     and not self.feed_has_expire(feed)) else False
Example #15
0
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,
    }
Example #16
0
 def feed_expire_status(self):
     tomorrow = get_tomommow()
     feed_has_expire = self.feed_expire_time < tomorrow
     return u'是' if feed_has_expire else u'否'
Example #17
0
 def feed_expire_status(self):
     tomorrow = get_tomommow()
     feed_has_expire = self.feed_expire_time < tomorrow
     return u'是' if feed_has_expire else u'否'