Пример #1
0
    def get(self):
        ps = config.KANCHENE
        ps['title'] = '%s%s' % ('首页', ps['pagetitle'])
        ps['date'] = datetime.now()        
        ps['top'] = {}
        ps['desc'] = ''
        r = redis.Redis(connection_pool=cachePool)
        key = '%smain' % (cacheKey)        
        ps['show'] = r.get(key)
	#print ps['show']
        if None == ps['show'] or ps['show'] == '[]':
            show = models.getProgramByID(363736)
            ps['show'] = show['program']
        else:
            ps['show'] = json.decode(ps['show'])[0]
        for top in toplist:
            key = '%s%s' % (cacheKey, top)
            programList = r.get(key)
            if None == programList:
                ps['top'][top] = models.getProgramsByTopList(config.KANCHENE['channel_key'][top], 10)
            else:
                ps['top'][top] = json.decode(programList)
            ps['top'][top] = formatProgram(ps['top'][top], 35)            
        ps['index'] = {}
        for index in indexlist:
            page = random.randint(1, 50)
            ps['index'][index] = models.getProgramsBySearch(config.KANCHENE['channel_key'][index], page, 8)
            ps['index'][index]['data'] = formatProgram(ps['index'][index]['data'], 20)
        self.render("index.htm", **ps)
Пример #2
0
def getProgramsByKey(key, start, size):    
    params = _bulidSearchParams(key, start=start, rows = size)
    content = http.get(config.KANCHENE['search_url'], params)
    if content is None:
        return None
    obj = json.decode(content)
    result = obj['response']['docs']
    return result
Пример #3
0
def getProgramsByTopList(key, size):
    start = random.randint(0, 50)
    params = _bulidSearchParams(key, start = start, rows = size)
    content = http.get(config.KANCHENE['search_url'], params)
    #print 'content:%s' % content
    if content is None:
        return None
    obj = json.decode(content)
    return obj['response']['docs']
Пример #4
0
def getProgramByID(pid):
    params = _bulidSearchByIDParams(pid, config.KANCHENE['relation_size'])
    content = http.get(config.KANCHENE['search_url'], params)
    if content is None:
        return None                
    obj = json.decode(content)
    if obj['response']['numFound'] < 1:
        return None
    program = {}
    program['program'] = obj['response']['docs'][0]
    program['relation'] = obj['moreLikeThis'][str(program['program']['id'])]['docs']
    return program
Пример #5
0
def getProgramsBySearch(key, page, size):
    if page is None or page < 0:
        page = 1        
    if size is None or size < 1:
        size = config.KANCHENE['size']
    start = (page - 1) * size
    params = _bulidSearchParams(key, start=start, rows = size)        
    content = http.get(config.KANCHENE['search_url'], params)
    if content is None:
        return None
        
    obj = json.decode(content)
    result = {}
    result['pageTotal'] = _getPageTotal(obj['response']['numFound'], size)
    result['page'] = page
    result['size'] = size
    result['time'] = obj['responseHeader']['QTime']
    result['total'] = obj['response']['numFound']
    result['data'] = obj['response']['docs']
    return result