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')
def post(self): self.response.headers['Content-Type'] = 'text/plain' data = json.loads(self.request.body) eventCriterion = globalconfig.getEventCriterion() twitterAccount = globalconfig.getTwitterAccount() key = data['key'] if key == 'sites': sitePages = snapi.getSitePages() matchedWords = _saveWords(key, data['words'], sitePages) heapi.summarizeEvents(eventCriterion, key, matchedWords, sitePages, twitterAccount) elif key == 'chartses': chartsPages = snapi.getChartsPages() matchedWords = _saveWords(key, data['words'], chartsPages) heapi.summarizeEvents(eventCriterion, key, matchedWords, chartsPages, twitterAccount) else: channel = globalconfig.getChannel(key) if not channel: logging.warn('Channel %s does not exist.' % (channel, )) elif not channel.get('tags'): logging.warn('Channel %s has no tags.' % (channel, )) else: sitePages = snapi.getSitePages() channelPages = snapi.getPagesByTags(sitePages, channel.get('tags')) if channelPages: matchedWords = _saveWords(key, data['words'], channelPages) heapi.summarizeEvents(eventCriterion, key, matchedWords, channelPages, twitterAccount) self.response.out.write('Done.')