Example #1
0
def audio_compress():
    id = kv_int.get(KV_PO_AUDIO)

    for i in ormiter(Po, 'cid=%s and id>%s'%(
        CID_AUDIO,
        id
    )):
        id = i.id

        input_filename = fs_file_audio(id)

        if not exists(input_filename):
            continue

        output_filename = '/tmp/po.audio.%s'%SITE_DOMAIN

        #if not isdir(output_filename):
        #    os.mkdir(output_filename)

        subprocess.call([
            'lame',
            '--quiet',
            '--mp3input',
            '--abr',
            '64',
            input_filename,
            output_filename
        ])

        if not exists(output_filename):
            continue

        shutil.move(output_filename, input_filename)

    kv_int.set(KV_PO_AUDIO, id)
def buzz_sys():
    prev_pos = kv_int.get(KV_BUZZ_SYS_POS)
    c = BuzzSys.raw_sql('select max(id) from buzz_sys')
    pos = c.fetchone()[0]
    if pos > prev_pos:
        c = BuzzSys.raw_sql('select id from buzz_sys where seq=0 and id>%s and id<=%s order by id', prev_pos, pos)
        for id, in c.fetchall():
            buzz_sys_new_all(id)
        kv_int.set(KV_BUZZ_SYS_POS, pos)
Example #3
0
def buzz_sys():
    prev_pos = kv_int.get(KV_BUZZ_SYS_POS)
    c = BuzzSys.raw_sql('select max(id) from buzz_sys')
    pos = c.fetchone()[0]
    if pos > prev_pos:
        c = BuzzSys.raw_sql(
            'select id from buzz_sys where seq=0 and id>%s and id<=%s order by id',
            prev_pos, pos)
        for id, in c.fetchall():
            buzz_sys_new_all(id)
        kv_int.set(KV_BUZZ_SYS_POS, pos)
def oauth_follow():
    rss_pos = kv_int.get(KV_OAUTH_FOLLOW)
    c = OauthToken.raw_sql('select max(id) from oauth_token')
    pos = c.fetchone()[0]
    if pos > rss_pos:
        c = OauthToken.raw_sql('select id from oauth_token where id>%s and id<=%s order by id', rss_pos, pos)
        for id, in c.fetchall():
            #print id
            #import sys
            #sys.stdout.flush()
            oauth_follow_by_oauth_id(id)
        kv_int.set(KV_OAUTH_FOLLOW, pos)
def oauth_follow():
    rss_pos = kv_int.get(KV_OAUTH_FOLLOW)
    c = OauthToken.raw_sql('select max(id) from oauth_token')
    pos = c.fetchone()[0]
    if pos > rss_pos:
        c = OauthToken.raw_sql(
            'select id from oauth_token where id>%s and id<=%s order by id',
            rss_pos, pos)
        for id, in c.fetchall():
            #print id
            #import sys
            #sys.stdout.flush()
            oauth_follow_by_oauth_id(id)
        kv_int.set(KV_OAUTH_FOLLOW, pos)
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)
Example #7
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)
def notice_reply():
    pre_pos = kv_int.get(KV_REPLY_NUM)

    #print pre_pos; pre_pos = 0

    c = Reply.raw_sql( 'select max(id) from reply where cid = %s', CID_NOTE)

    pos = c.fetchone()[0]

    if pos > pre_pos:
        d = defaultdict(set)

        for i in Reply.where(cid=CID_NOTE).where( 'id>%s and id<=%s', pre_pos, pos):
            po_id = i.rid
            user_id = i.user_id
            d[po_id].add(user_id)

        for po_id, li in d.iteritems():
            reply_notice_mail(po_id, li)

        kv_int.set(KV_REPLY_NUM, pos)
Example #9
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)
Example #11
0
def notice_reply():
    pre_pos = kv_int.get(KV_REPLY_NUM)

    #print pre_pos; pre_pos = 0

    c = Reply.raw_sql('select max(id) from reply where cid = %s', CID_NOTE)

    pos = c.fetchone()[0]

    if pos > pre_pos:
        d = defaultdict(set)

        for i in Reply.where(cid=CID_NOTE).where('id>%s and id<=%s', pre_pos,
                                                 pos):
            po_id = i.rid
            user_id = i.user_id
            d[po_id].add(user_id)

        for po_id, li in d.iteritems():
            reply_notice_mail(po_id, li)

        kv_int.set(KV_REPLY_NUM, pos)
def invite_message():
    pre_pos = kv_int.get(KV_INVITE_MESSAGE)
    #print pre_pos
    c = InviteMessage.raw_sql( 'select max(id) from invite_message')
    pos = c.fetchone()[0]
    if pos > pre_pos:
        for m in InviteMessage.where('id>%s and id<=%s', pre_pos, pos):
            email_list = loads( m.email )
            invitor = Zsite.mc_get(m.user_id)

            txt = m.txt

            for email in email_list:
                if '@' not in email:
                    continue
                email = email.split(' ', 1)
                if len(email) == 2:
                    email , name = email
                else:
                    email = email[0]
                    name = email.split('@', 1)[0]

                #print email
                #raw_input(email)
                #email = "*****@*****.**"

                rendermail(
                    '/mail/invite/invite_message.txt',
                    email,
                    name,
                    invitor=invitor,
                    sender_name=invitor.name,
                    txt=txt
                )

        kv_int.set(KV_INVITE_MESSAGE, pos)