def event_weekly_mail(user, event_city_list, write_mail):
    user_id = user.id
    if mail_notice_state(user_id, CID_MAIL_WEEK):
        mail = mail_by_user_id(user_id)
        #print user_id
        #sys.stdout.flush()
        if mail:
            title = [
            ]
            if not write_mail or not write_mail.title:
                title.append('线下活动 . 周报汇总')
            else:
                title.append('%s ;'%write_mail.title )

            pid = 0
            namecard = namecard_get(user_id)
            if namecard:
                pid_now = namecard.pid_now
                if pid_now:
                    pid = pid_city(pid_now)
            event_city_list, event_incr, place = event_city_info(event_city_list, pid)

            if event_incr:
                title.append(
                    '%s +%s 活动' % (place, event_incr)
                )

            if not write_mail or not write_mail.title:
                title.append(today_cn_date())
                title = ' . '.join(title)
            else:
                title = ' '.join(title)

            name = user.name
            if write_mail and write_mail.txt:
                htm = txt_withlink(write_mail.txt).replace('\r', '</p><p>')
                htm = '<p>%s</p>'%htm
            else:
                htm = None

            #print mail
            #mail = '*****@*****.**'
            #raw_input()

            rendermail(
                '/mail/event/weekly.htm',
                mail,
                name,
                event_city_list=event_city_list,
                write_htm=htm,
                format='html',
                subject=title
            )
Esempio n. 2
0
def event_weekly_mail(user, event_city_list, write_mail):
    user_id = user.id
    if mail_notice_state(user_id, CID_MAIL_WEEK):
        mail = mail_by_user_id(user_id)
        #print user_id
        #sys.stdout.flush()
        if mail:
            title = []
            if not write_mail or not write_mail.title:
                title.append('线下活动 . 周报汇总')
            else:
                title.append('%s ;' % write_mail.title)

            pid = 0
            namecard = namecard_get(user_id)
            if namecard:
                pid_now = namecard.pid_now
                if pid_now:
                    pid = pid_city(pid_now)
            event_city_list, event_incr, place = event_city_info(
                event_city_list, pid)

            if event_incr:
                title.append('%s +%s 活动' % (place, event_incr))

            if not write_mail or not write_mail.title:
                title.append(today_cn_date())
                title = ' . '.join(title)
            else:
                title = ' '.join(title)

            name = user.name
            if write_mail and write_mail.txt:
                htm = txt_withlink(write_mail.txt).replace('\r', '</p><p>')
                htm = '<p>%s</p>' % htm
            else:
                htm = None

            #print mail
            #mail = '*****@*****.**'
            #raw_input()

            rendermail('/mail/event/weekly.htm',
                       mail,
                       name,
                       event_city_list=event_city_list,
                       write_htm=htm,
                       format='html',
                       subject=title)
def buzz_follow_mail():
    prev_pos = kv_int.get(KV_BUZZ_FOLLOW_POS)
    c = Buzz.raw_sql(
        'select max(id) from buzz where create_time<%s', int(time()) - ONE_DAY
    )
    pos = c.fetchone()[0]
    if pos > prev_pos:
        d = defaultdict(OrderedDict)

        for i in Buzz.where(cid=CID_BUZZ_FOLLOW).where('to_id=rid').where(
            'id>%s and id<=%s', prev_pos, pos
        ):
            id = i.id
            d[i.to_id][i.from_id] = i.id

        dd = defaultdict(OrderedSet)
        for to_id, _d in d.iteritems():
            if mail_notice_state(to_id, CID_BUZZ_FOLLOW):
                min_id = buzz_pos.get(to_id)
                for from_id, id in _d.iteritems():
                    if id > min_id:
                        dd[to_id].add(from_id)


        for to_id, li in dd.iteritems():

            mail = mail_by_user_id(to_id)
            name = Zsite.mc_get(to_id).name

            for from_id in li:

                from_user = Zsite.mc_get(from_id)
                career = from_user.career
                if from_user.state >= ZSITE_STATE_VERIFY and any(career):
                    rendermail(
                        '/mail/buzz/follow_new.htm', mail, name,
                        from_user=from_user,
                        format='html',
                        subject='%s ( %s ) 关注 你' % (
                            from_user.name,
                            ' , '.join(career),
                        )
                    )
                    #sleep(0.1)

        kv_int.set(KV_BUZZ_FOLLOW_POS, pos)
Esempio n. 4
0
def buzz_follow_mail():
    prev_pos = kv_int.get(KV_BUZZ_FOLLOW_POS)
    c = Buzz.raw_sql('select max(id) from buzz where create_time<%s',
                     int(time()) - ONE_DAY)
    pos = c.fetchone()[0]
    if pos > prev_pos:
        d = defaultdict(OrderedDict)

        for i in Buzz.where(cid=CID_BUZZ_FOLLOW).where('to_id=rid').where(
                'id>%s and id<=%s', prev_pos, pos):
            id = i.id
            d[i.to_id][i.from_id] = i.id

        dd = defaultdict(OrderedSet)
        for to_id, _d in d.iteritems():
            if mail_notice_state(to_id, CID_BUZZ_FOLLOW):
                min_id = buzz_pos.get(to_id)
                for from_id, id in _d.iteritems():
                    if id > min_id:
                        dd[to_id].add(from_id)

        for to_id, li in dd.iteritems():

            mail = mail_by_user_id(to_id)
            name = Zsite.mc_get(to_id).name

            for from_id in li:

                from_user = Zsite.mc_get(from_id)
                career = from_user.career
                if from_user.state >= ZSITE_STATE_VERIFY and any(career):
                    rendermail('/mail/buzz/follow_new.htm',
                               mail,
                               name,
                               from_user=from_user,
                               format='html',
                               subject='%s ( %s ) 关注 你' % (
                                   from_user.name,
                                   ' , '.join(career),
                               ))
                    #sleep(0.1)

        kv_int.set(KV_BUZZ_FOLLOW_POS, pos)
Esempio n. 5
0
def notice_day():
    prev_pos = kv_int.get(KV_NOTICE_POS)
    c = Notice.raw_sql('select max(id) from notice where create_time<%s',
                       today_seconds())
    pos = c.fetchone()[0]
    if pos > prev_pos:
        d = defaultdict(OrderedSet)

        for i in Notice.where(state=STATE_APPLY).where('id>%s and id<=%s',
                                                       prev_pos, pos):
            cid = i.cid
            to_id = i.to_id
            if cid in NOTICE_MAIL_DAY and mail_notice_state(
                    to_id, CID_MAIL_DAY):
                d[to_id].add((i.from_id, cid, i.rid))

        for to_id, li in d.iteritems():
            notice_mail_day(to_id, li)
            sleep(0.1)

        kv_int.set(KV_NOTICE_POS, pos)
def notice_day():
    prev_pos = kv_int.get(KV_NOTICE_POS)
    c = Notice.raw_sql(
        'select max(id) from notice where create_time<%s', today_seconds()
    )
    pos = c.fetchone()[0]
    if pos > prev_pos:
        d = defaultdict(OrderedSet)

        for i in Notice.where(state=STATE_APPLY).where(
            'id>%s and id<=%s', prev_pos, pos
        ):
            cid = i.cid
            to_id = i.to_id
            if cid in NOTICE_MAIL_DAY and mail_notice_state(to_id, CID_MAIL_DAY):
                d[to_id].add((i.from_id, cid, i.rid))

        for to_id, li in d.iteritems():
            notice_mail_day(to_id, li)
            sleep(0.1)

        kv_int.set(KV_NOTICE_POS, pos)