示例#1
0
    def get(self):
        _LATEST_COUNT = 6
        sitePages = snapi.getSitePages()
        sitePages = [ page for page in sitePages if page['rank'] == 1 ]
        homeTags = globalconfig.getHomeTags()
        for homeTag in homeTags:
            homeTag['pages'] = snapi.getPagesByTags(sitePages, homeTag['tags'])
            homeTag['pages'].sort(key=lambda page: page.get('published') or page['added'], reverse=True)
            homeTag['pages'] = homeTag['pages'][:_LATEST_COUNT]
            globalutil.populateSourceUrl(homeTag['pages'])

        channels = globalconfig.getChannels()
        for channel in channels:
            slug = channel.get('slug')
            channel['url'] = webapp2.uri_for('channel', channel=slug)

            tags = channel.get('tags')
            channel['pages'] = bs.getPagesByTags(sitePages, tags)

            channel['pages'].sort(key=lambda page: page['added'], reverse=True)
            channel['pages'] = channel['pages'][:_LATEST_COUNT]
            globalutil.populateSourceUrl(channel['pages'])

        templateValues = {
            'homeTags': homeTags,
            'channels': channels,
        }
        self.render(templateValues, 'latest.html')
示例#2
0
    def get(self, channel):
        foundChannel = globalconfig.getChannel(channel)

        if not foundChannel:
            self.error(404)
            return

        sitePages = snapi.getSitePages()
        tags = foundChannel.get('tags')
        channelPages = bs.getPagesByTags(sitePages, tags)

        foundChannel['groups'] = []
        for group in models.getChannelGroups(channel):
            group['pages'] = bs.getPagesByTags(channelPages, group['tags'])
            globalutil.populateSourceUrl(group['pages'])
            group['pages'].sort(key=lambda page: page['added'], reverse=True)
            if group['pages']:
                foundChannel['groups'].append(group)

        words, pages = hwapi.getWords(foundChannel['slug'])
        pages.sort(key=lambda page: page['weight'], reverse=True)

        templateValues = {
            'words': words,
            'pages': pages,
            'channel': foundChannel,
        }
        self.render(templateValues, 'channel.html')
示例#3
0
    def get(self):
        _LATEST_COUNT = 6

        channels = globalconfig.getChannels()
        for channel in channels:
            slug = channel.get('slug')
            channel['url'] = webapp2.uri_for('channel', channel=slug)

            events = heapi.getEventPages(slug)
            for page in events:
                if page['event']['exposed']:
                    eventUrlType = 'event'
                else:
                    eventUrlType = 'hidden-event'
                # if eventId=0, error happens: 'Missing argument "eventId" to build URI.'
                page['event']['url'] = webapp2.uri_for(eventUrlType, eventScope=slug, eventId=page['event']['id'])
            events.sort(key=lambda page: page['weight'], reverse=True)
            events = events[:_LATEST_COUNT]
            globalutil.populateSourceUrl(events)
            channel['events'] = events

        chartses = snapi.getChartses()
        chartses.sort(key=lambda charts: charts['source']['added'], reverse=True)
        for charts in chartses:
            charts['url'] = webapp2.uri_for('charts', charts=charts['source']['slug'])
            charts['pages'] = charts['pages'][:_LATEST_COUNT]

        templateValues = {
            'channels': channels,
            'chartses': chartses,
        }
        self.render(templateValues, 'home.html')
示例#4
0
    def get(self, keyword):
        pages = []
        spages = []
        words = []
        if keyword:
            import jieba # May fail to load jieba
            jieba.initialize(usingSmall=True)
            words = list(jieba.cut(keyword, cut_all=False))
            words = [ word for word in words if len(word) > 1 ]
            # words = list(jieba.cut_for_search(keyword))
            keyword = stringutil.parseUnicode(keyword)
            pages = snapi.getAllPages()
            pages = globalutil.search(pages, words)
            globalutil.populateSourceUrl(pages)

            twitterAccount = globalconfig.getTwitterAccount()
            spages = bs.search(words[0], twitterAccount)

        templateValues = {
            'keyword': keyword,
            'pages': pages,
            'spages': spages,
            'words': words,
        }
        self.render(templateValues, 'search.html')
示例#5
0
 def get(self):
     words, pages = hwapi.getWords('sites')
     pages.sort(key=lambda page: page['weight'], reverse=True)
     globalutil.populateSourceUrl(pages)
     templateValues = {
         'words': words,
         'pages': pages,
     }
     self.render(templateValues, 'sites.html')
示例#6
0
    def get(self):
        siteEvents = heapi.getEventPages('sites')
        for page in siteEvents:
            if page['event']['exposed']:
                eventUrlType = 'event'
            else:
                eventUrlType = 'hidden-event'
            # if eventId=0, error happens: 'Missing argument "eventId" to build URI.'
            page['event']['url'] = webapp2.uri_for(eventUrlType, eventScope='sites', eventId=page['event']['id'])
        siteEvents.sort(key=lambda page: page['weight'], reverse=True)
        globalutil.populateSourceUrl(siteEvents)

        chartsEvents = heapi.getEventPages('chartses')
        for page in chartsEvents:
            if page['event']['exposed']:
                eventUrlType = 'event'
            else:
                eventUrlType = 'hidden-event'
            # if eventId=0, error happens: 'Missing argument "eventId" to build URI.'
            page['event']['url'] = webapp2.uri_for(eventUrlType, eventScope='chartses', eventId=page['event']['id'])
        chartsEvents.sort(key=lambda page: page['weight'], reverse=True)

        _LATEST_COUNT = 10
        chartses = snapi.getChartses()
        chartses.sort(key=lambda charts: charts['source']['added'], reverse=True)
        for charts in chartses:
            charts['url'] = webapp2.uri_for('charts', charts=charts['source']['slug'])
            charts['pages'] = charts['pages'][:_LATEST_COUNT]


        templateValues = {
            'siteEvents': siteEvents,
            'chartsEvents': chartsEvents,
            'chartses': chartses,
        }
        self.render(templateValues, 'hot.html')