Esempio n. 1
0
def po_json(user_id, po_id_list, line_width):

    po_id_list = map(int,po_id_list)

    po_list = Po.mc_get_list(po_id_list)

    txt_bind(po_list)

    Zsite.mc_bind(po_list, 'user', 'user_id')
    result = []


    fav_dict = fav_cid_dict(
        user_id,
        po_id_list
    )

    for po in po_list:

        name = po.name
        user = po.user


        name_len = cnenlen(name)
        txt = po.txt

        if txt and name_len < line_width:
            tip = cnenoverflow(txt, line_width-name_len)[0]
        else:
            tip = ''

        id = po.id
        if not user:
            user_id = 0
            user_name = None
        else:
            user_id = user.id
            user_name = None
        result.append((
            id,
            name,
            tip,
#            user_id,
#            user_name,
            fav_dict[id]
        ))
# 0   1       2     3           4               5
# id , name, tip,  author_id , author_name , is_star 
    return result
Esempio n. 2
0
def po_json(user_id, po_id_list, line_width):

    po_id_list = map(int, po_id_list)

    po_list = Po.mc_get_list(po_id_list)

    txt_bind(po_list)

    Zsite.mc_bind(po_list, 'user', 'user_id')
    result = []

    fav_dict = fav_cid_dict(user_id, po_id_list)

    for po in po_list:

        name = po.name
        user = po.user

        name_len = cnenlen(name)
        txt = po.txt

        if txt and name_len < line_width:
            tip = cnenoverflow(txt, line_width - name_len)[0]
        else:
            tip = ''

        id = po.id
        if not user:
            user_id = 0
            user_name = None
        else:
            user_id = user.id
            user_name = None
        result.append((
            id,
            name,
            tip,
            #            user_id,
            #            user_name,
            fav_dict[id]))


# 0   1       2     3           4               5
# id , name, tip,  author_id , author_name , is_star
    return result
Esempio n. 3
0
def oauth_txt_cat(cid, txt, url=None):
    txt = PIC_SUB.sub('', txt)

    if url:
        url_len = len(str(url))
    else:
        url_len = 0

    if cid == OAUTH_DOUBAN:
        txt = str(txt).decode('utf-8')
        tword = txt[:140-url_len]
        if tword != txt:
            txt = txt[:137-url_len]+'...'
    else:
        txt = cnenoverflow(str(txt), 139-url_len)[0]

    if url:
        txt = '%s %s'%(txt, url)

    return txt
Esempio n. 4
0
def zsite_json(zsite_id, zsite_list):
    ico_url_bind(zsite_list)
    zsite_id_list = tuple(i.id for i in zsite_list)

    user_list = []
    for i in zsite_list:
        if i.cid == CID_USER:
            user_list.append(i)
    career_bind(user_list)

    motto_dict = motto.get_dict(zsite_id_list)

    result = []

    for i, is_follow in zip(
        zsite_list,
        follow_get_list(zsite_id, zsite_id_list)
    ):
        career = (' , '.join(filter(bool, i.career)) if i.cid==CID_USER else 0) or 0
        _motto = motto_dict.get(i.id) or 0
        if _motto:
            length = 14
            if not career:
                length += length
            _motto = cnenoverflow(_motto, length)[0]

        if is_follow and is_follow is not True:
            is_follow = 1
        result.append((
            i.id, #0 
            i.link, #1
            i.name, #2
            i.ico, #3
            career, #4
            i.cid , #5
            _motto , #6
            is_follow , #7
        ))

    return result
Esempio n. 5
0
def zsite_json(zsite_id, zsite_list):
    ico_url_bind(zsite_list)
    zsite_id_list = tuple(i.id for i in zsite_list)

    user_list = []
    for i in zsite_list:
        if i.cid == CID_USER:
            user_list.append(i)
    career_bind(user_list)

    motto_dict = motto.get_dict(zsite_id_list)

    result = []

    for i, is_follow in zip(zsite_list,
                            follow_get_list(zsite_id, zsite_id_list)):
        career = (' , '.join(filter(bool, i.career))
                  if i.cid == CID_USER else 0) or 0
        _motto = motto_dict.get(i.id) or 0
        if _motto:
            length = 14
            if not career:
                length += length
            _motto = cnenoverflow(_motto, length)[0]

        if is_follow and is_follow is not True:
            is_follow = 1
        result.append((
            i.id,  #0 
            i.link,  #1
            i.name,  #2
            i.ico,  #3
            career,  #4
            i.cid,  #5
            _motto,  #6
            is_follow,  #7
        ))

    return result
Esempio n. 6
0
def feed_tuple_by_db(id):
    m = Po.mc_get(id)
    if not m:
        feed_rm(id)
    cid = m.cid
    rid = m.rid
    has_question = cid in (CID_WORD, CID_ANSWER)

    if rid and has_question:
        question = m.target
        name = question.name
    elif cid == CID_REC:
        name = m.name_htm
    elif cid != CID_WORD:
        name = m.name
    else:
        name = None

    #if cid == CID_QUESTION:
    #    reply_count = answer_count(id)
    #else:
    reply_count = m.reply_count
    if cid == CID_PHOTO:
        rid = fs_url_jpg(721, rid)
    elif cid == CID_AUDIO:
        rid = fs_url_audio(id, '')
    elif cid == CID_VIDEO:
        rid = video_link_autoplay(rid, id)
    elif cid == CID_EVENT:
        event = Event.mc_get(id)
        feed_rm(id)
        rid = fs_url_jpg(162, event.pic_id)
    else:
        rid = rid

    result = [
        m.user_id,
        cid,
        rid,
        m.zsite_id,
        reply_count,
        m.create_time,
        name,
        #vote_count(id)
    ]

    txt = m.txt
    if cid != CID_WORD:
        txt, has_more = cnenoverflow(txt, 100)
        if not has_more:
            txt = m.htm
        result.extend((txt, has_more))
    else:
        txt = txt_withlink(txt)
        result.extend((txt, False))

    if cid == CID_EVENT:
        result.append(place_name(event.pid))
        result.append(event.address)
        result.extend(begin_end_by_minute(event.begin_time, event.end_time))
    elif rid and has_question:
        user = question.user
        result.extend((question.id, user.name, user.link))

    return result
Esempio n. 7
0
def feed_tuple_by_db(id):
    m = Po.mc_get(id)
    if not m:
        feed_rm(id)
    cid = m.cid
    rid = m.rid
    has_question = cid in (CID_WORD, CID_ANSWER)

    if rid and has_question:
        question = m.target
        name = question.name
    elif cid == CID_REC:
        name = m.name_htm
    elif cid != CID_WORD:
        name = m.name
    else:
        name = None

    #if cid == CID_QUESTION:
    #    reply_count = answer_count(id)
    #else:
    reply_count = m.reply_count
    if cid == CID_PHOTO:
        rid = fs_url_jpg(721, rid)
    elif cid == CID_AUDIO:
        rid = fs_url_audio(id, '')
    elif cid == CID_VIDEO:
        rid = video_link_autoplay(rid, id)
    elif cid == CID_EVENT:
        event = Event.mc_get(id)
        feed_rm(id)
        rid = fs_url_jpg(162, event.pic_id)
    else:
        rid = rid

    result = [
        m.user_id,
        cid,
        rid,
        m.zsite_id,
        reply_count,
        m.create_time,
        name,
        #vote_count(id)
    ]

    txt = m.txt
    if cid != CID_WORD:
        txt, has_more = cnenoverflow(txt, 100)
        if not has_more:
            txt = m.htm
        result.extend((txt, has_more))
    else:
        txt = txt_withlink(txt)
        result.extend((txt, False))

    if cid == CID_EVENT:
        result.append(place_name(event.pid))
        result.append(event.address)
        result.extend(
            begin_end_by_minute(event.begin_time, event.end_time)
        )
    elif rid and has_question:
        user = question.user
        result.extend(
            (question.id, user.name, user.link)
        )

    return result