Ejemplo n.º 1
0
def getFeedInfo ( type, feedPars, nocache = False ):
    status = 0
    msg = ''
    content = None 

    #首先从cache获取内容
#    cache_key = getFeedInfoCacheKey( feedPars )
#    if not nocache :
#        content = getFeedInfo_FromCache( cache_key )

#    if content != None:
#        try:
#            return (0, '', json.loads( content, strict=False ))
#        except:
#            logger.error( 'getFeedInfo, json load faild, key=%s, feedPars=%s, err=%s', cache_key, str(feedPars), str(sys.exc_info()) )

    logger.debug( 'getFeedInfo from third interface, feedPars=%s', str(feedPars) )

    # cache没有发现,则调用内容获取接口
    if type == 'news':
        # 新闻不用做ID转换
        content = news_interface.getNewsContent( feedPars['id'] )
        if content == None or len(content) <=0 :
            (status,msg,content) =  ( -1, 'get new content faild', None )
    elif type == 'video' :
        # 视频不用做ID转换
        (status,msg,content) = video_interface.video_interface( feedPars )
#    elif type == 'music' :
        #(status,msg,content) = music_interface.Music_interface.Get_music_detail( srcContId )
#        pass
    elif type == 'story' :
        if str(feedPars['info_type']) != '2':
            # 需要取得源ID
            srcid = getMiniFeedDataSrcId( feedPars['id'] )
        else:
            srcid = feedPars['id']
        
        if srcid == None or srcid == '' :
            (status,msg,content) =  ( -1, 'id is invalid', None )
        else:
            feedPars['id'] = srcid
            novel_reader_obj = novel_reader.NovelReader()
            (status,msg,content) = novel_reader_obj.fetch_novel_info( feedPars )
    else:
        (status,msg,content) = ( -1,'input type invalid', None)
        
    if status == 0:
        pass
#        updateFeedInfo_ToCache( cache_key, json.dumps(content) )
    else:
        logger.error( 'getFeedInfo from third interface faild, msg=%s' % msg )

    return (status, msg, content)
Ejemplo n.º 2
0
def getFeedContent ( contId, nocache = False ):
    #首先从cache获取内容
    content = None
    if not nocache :
        content = getFeedContent_FromCache( contId )

    if content != None:
        try:
            return json.loads( content, strict=False )
        except:
            logger.error( 'getFeedContent, json load faild, id=%s, err=%s', contId, str(sys.exc_info()) )

    logger.debug( 'getFeedContent from third interface, id=%s', contId )

    # cache没有发现,则调用内容获取接口
    if isinstance( contId, unicode ):
        contId = contId.encode( 'utf8' )
    
    p = contId.find( '_' )
    if p < 0 :
        logger.error( "getFeedContent, id is invalid, id=%s", contId )
        return {}

    cat = contId[0:p]
    srcContId = contId[p+1:]

    status = 0
    msg = ''
    content = {}

    if cat == 'news':
        content = news_interface.getNewsContent( srcContId )
    elif cat == 'video' :
        (status,msg,content) = video_interface.video_interface( {'id':srcContId, 'info_type':2} )
    elif cat == 'music' :
        content = music_interface.Music_interface.Get_music_detail( srcContId )
    elif cat == 'story' :
        novel_reader_obj = novel_reader.NovelReader()
        (status,msg,content) = novel_reader_obj.fetch_novel_info( {'id':srcContId, 'info_type':1} )
        
    if content == None or len(content) == 0 :
        logger.error( "getFeedContent faild, id=%s", contId )
        return {}

    updateFeedContent_ToCache( contId, json.dumps(content) )
    return content