Get top keywords categories
3297
def get_cats(self):
        ''''''
        start_url = 'http://top.taobao.com/index.php?from=tbsy'
        rs = self.fetch(start_url)
        if not rs: return None
        soup = BeautifulSoup(rs.content, convertEntities=BeautifulSoup.HTML_ENTITIES, markupMassage=hexentityMassage)
        cats = [{'id':'TR_%s'%li['id'].encode('utf-8').upper(), 'title':li.a.text.encode('utf-8').strip()} for li in soup.find('div', id='nav').findAll('li') if li['id']!='index']
        threadPool = ThreadPool(len(cats) if len(cats)<=5 else 5)
        for cat in cats:
            threadPool.run(self.get_cats_thread, callback=None, cat=cat)
        cats = threadPool.killAllWorkers(None)
        return cats
79069
function processKeywords() {
    var nodes = []
    var lastIndex
    var keyword
    var node
    var submatch

    if (!top.keywords) {
      return addText(modeBuffer, nodes)
    }

    lastIndex = 0

    top.lexemesRe.lastIndex = 0

    keyword = top.lexemesRe.exec(modeBuffer)

    while (keyword) {
      addText(modeBuffer.substring(lastIndex, keyword.index), nodes)

      submatch = keywordMatch(top, keyword)

      if (submatch) {
        relevance += submatch[1]

        node = build(submatch[0], [])

        nodes.push(node)

        addText(keyword[0], node.children)
      } else {
        addText(keyword[0], nodes)
      }

      lastIndex = top.lexemesRe.lastIndex
      keyword = top.lexemesRe.exec(modeBuffer)
    }

    addText(modeBuffer.substr(lastIndex), nodes)

    return nodes
  }
907676
def top_charts(self):
		""""""

		response = self._call(mc_calls.BrowseTopChart)
		top_charts = response.body

		return top_charts
518428
def get_top_tags(self, limit=None):
        """"""

        doc = self._request(self.ws_prefix + ".getTopTags", True)

        elements = doc.getElementsByTagName("tag")
        seq = []

        for element in elements:
            tag_name = _extract(element, "name")
            tagcount = _extract(element, "count")

            seq.append(TopItem(Tag(tag_name, self.network), tagcount))

        if limit:
            seq = seq[:limit]

        return seq
16307
def get_categories(self):
        
        sdb_resp = get_with_retry(self.cerberus_url + '/v1/category',
                                headers=self.HEADERS)

        throw_if_bad_response(sdb_resp)
        return sdb_resp.json()
1318483
def categories(self):
        
        r = [ch for ch in self._channels.values() if isinstance(ch, CategoryChannel)]
        r.sort(key=lambda c: (c.position, c.id))
        return r
677321
def get_tops(self):
        '''
        
        '''
        tops = DefaultOrderedDict(list)
        include = DefaultOrderedDict(list)
        done = DefaultOrderedDict(list)
        found = 0  # did we find any contents in the top files?
        # Gather initial top files
        merging_strategy = self.opts['top_file_merging_strategy']
        if merging_strategy == 'same' and not self.opts['saltenv']:
            if not self.opts['default_top']:
                raise SaltRenderError(
                    'top_file_merging_strategy set to \'same\', but no '
                    'default_top configuration option was set'
                )

        if self.opts['saltenv']:
            contents = self.client.cache_file(
                self.opts['state_top'],
                self.opts['saltenv']
            )
            if contents:
                found = 1
                tops[self.opts['saltenv']] = [
                    compile_template(
                        contents,
                        self.state.rend,
                        self.state.opts['renderer'],
                        self.state.opts['renderer_blacklist'],
                        self.state.opts['renderer_whitelist'],
                        saltenv=self.opts['saltenv']
                    )
                ]
            else:
                tops[self.opts['saltenv']] = [{}]

        else:
            found = 0
            state_top_saltenv = self.opts.get('state_top_saltenv', False)
            if state_top_saltenv \
                    and not isinstance(state_top_saltenv, six.string_types):
                state_top_saltenv = six.text_type(state_top_saltenv)

            for saltenv in [state_top_saltenv] if state_top_saltenv \
                    else self._get_envs():
                contents = self.client.cache_file(
                    self.opts['state_top'],
                    saltenv
                )
                if contents:
                    found = found + 1
                    tops[saltenv].append(
                        compile_template(
                            contents,
                            self.state.rend,
                            self.state.opts['renderer'],
                            self.state.opts['renderer_blacklist'],
                            self.state.opts['renderer_whitelist'],
                            saltenv=saltenv
                        )
                    )
                else:
                    tops[saltenv].append({})
                    log.debug('No contents loaded for saltenv \'%s\'', saltenv)

            if found > 1 and merging_strategy == 'merge' and not self.opts.get('env_order', None):
                log.warning(
                    'top_file_merging_strategy is set to \'%s\' and '
                    'multiple top files were found. Merging order is not '
                    'deterministic, it may be desirable to either set '
                    'top_file_merging_strategy to \'same\' or use the '
                    '\'env_order\' configuration parameter to specify the '
                    'merging order.', merging_strategy
                )

        if found == 0:
            log.debug(
                'No contents found in top file. If this is not expected, '
                'verify that the \'file_roots\' specified in \'etc/master\' '
                'are accessible. The \'file_roots\' configuration is: %s',
                repr(self.state.opts['file_roots'])
            )

        # Search initial top files for includes
        for saltenv, ctops in six.iteritems(tops):
            for ctop in ctops:
                if 'include' not in ctop:
                    continue
                for sls in ctop['include']:
                    include[saltenv].append(sls)
                ctop.pop('include')
        # Go through the includes and pull out the extra tops and add them
        while include:
            pops = []
            for saltenv, states in six.iteritems(include):
                pops.append(saltenv)
                if not states:
                    continue
                for sls_match in states:
                    for sls in fnmatch.filter(self.avail[saltenv], sls_match):
                        if sls in done[saltenv]:
                            continue
                        tops[saltenv].append(
                            compile_template(
                                self.client.get_state(
                                    sls,
                                    saltenv
                                ).get('dest', False),
                                self.state.rend,
                                self.state.opts['renderer'],
                                self.state.opts['renderer_blacklist'],
                                self.state.opts['renderer_whitelist'],
                                saltenv
                            )
                        )
                        done[saltenv].append(sls)
            for saltenv in pops:
                if saltenv in include:
                    include.pop(saltenv)
        return tops
852886
def get_categories(blog_id, username, password):
    
    authenticate(username, password)
    site = Site.objects.get_current()
    return [category_structure(category, site)
            for category in Category.objects.all()]
232848
def top_level(self):
        
        output = {}
        if isinstance(self.obj, dict):
            for name, item in self.obj.items():
                if isinstance(item, dict):
                    if item:
                        output[name] = StrReprWrapper('{...}')
                    else:
                        output[name] = StrReprWrapper('{}')
                elif isinstance(item, list):
                    if item:
                        output[name] = StrReprWrapper('[...]')
                    else:
                        output[name] = StrReprWrapper('[]')
                else:
                    output[name] = item
            return output
        else:
            return self.obj
59277
public function getCategories() {
    $cid = __METHOD__;
    if ($cache = $this->cache->get($cid)) {
      return $cache->data;
    }

    $link = $this->getUrlFromOpenyProgramsSearchSettings('get_categories_path');
    $result = $this->scrapeCategoryList($link);
    $data = array_combine(array_values($result), array_values($result));

    $this->cache->set($cid, $data);
    return $data;
  }
149455
def filter_core_keywords(keywords):
    """"""
    matches = {}
    for kw, info in keywords.items():
        if kw.core:
            matches[kw] = info
    return matches
871376
def get_keywords(self):
        
        keywords = {}
        inasafe_fields = {}
        keywords['layer_geometry'] = self.get_layer_geometry_key()
        if self.step_kw_purpose.selected_purpose():
            keywords['layer_purpose'] = self.step_kw_purpose.\
                selected_purpose()['key']
        if self.step_kw_subcategory.selected_subcategory():
            key = self.step_kw_purpose.selected_purpose()['key']
            keywords[key] = self.step_kw_subcategory.\
                selected_subcategory()['key']
        if self.get_layer_geometry_key() == layer_geometry_raster['key']:
            if self.step_kw_band_selector.selected_band():
                keywords['active_band'] = self.step_kw_band_selector.\
                    selected_band()
        if keywords['layer_purpose'] == layer_purpose_hazard['key']:
            if self.step_kw_hazard_category.selected_hazard_category():
                keywords['hazard_category'] \
                    = self.step_kw_hazard_category.\
                    selected_hazard_category()['key']
        if self.step_kw_layermode.selected_layermode():
            keywords['layer_mode'] = self.step_kw_layermode.\
                selected_layermode()['key']
        if self.step_kw_unit.selected_unit():
            if self.step_kw_purpose.selected_purpose() == layer_purpose_hazard:
                key = continuous_hazard_unit['key']
            else:
                key = exposure_unit['key']
            keywords[key] = self.step_kw_unit.selected_unit()['key']
        if self.step_kw_field.selected_fields():
            field_key = self.field_keyword_for_the_layer()
            inasafe_fields[field_key] = self.step_kw_field.selected_fields()
        if self.step_kw_classification.selected_classification():
            keywords['classification'] = self.step_kw_classification.\
                selected_classification()['key']

        if keywords['layer_purpose'] == layer_purpose_hazard['key']:
            multi_classifications = self.step_kw_multi_classifications.\
                get_current_state()
            value_maps = multi_classifications.get('value_maps')
            if value_maps is not None:
                keywords['value_maps'] = value_maps
            thresholds = multi_classifications.get('thresholds')
            if thresholds is not None:
                keywords['thresholds'] = thresholds
        else:
            if self.step_kw_layermode.selected_layermode():
                layer_mode = self.step_kw_layermode.selected_layermode()
                if layer_mode == layer_mode_continuous:
                    thresholds = self.step_kw_threshold.get_threshold()
                    if thresholds:
                        keywords['thresholds'] = thresholds
                elif layer_mode == layer_mode_classified:
                    value_map = self.step_kw_classify.selected_mapping()
                    if value_map:
                        keywords['value_map'] = value_map

        if self.step_kw_source.leSource.text():
            keywords['source'] = self.step_kw_source.leSource.text()
        if self.step_kw_source.leSource_url.text():
            keywords['url'] = self.step_kw_source.leSource_url.text()
        if self.step_kw_source.leSource_scale.text():
            keywords['scale'] = self.step_kw_source.leSource_scale.text()
        if self.step_kw_source.ckbSource_date.isChecked():
            keywords['date'] = self.step_kw_source.dtSource_date.dateTime()
        if self.step_kw_source.leSource_license.text():
            keywords['license'] = self.step_kw_source.leSource_license.text()
        if self.step_kw_title.leTitle.text():
            keywords['title'] = self.step_kw_title.leTitle.text()

        inasafe_fields.update(self.step_kw_inasafe_fields.get_inasafe_fields())
        inasafe_fields.update(
            self.step_kw_default_inasafe_fields.get_inasafe_fields())
        inasafe_fields.update(
            self.step_kw_fields_mapping.get_field_mapping()['fields'])

        if inasafe_fields:
            keywords['inasafe_fields'] = inasafe_fields

        inasafe_default_values = {}
        if keywords['layer_geometry'] == layer_geometry_raster['key']:
            pass
            # Notes(IS): Skipped assigning raster inasafe default value for
            # now.
            # inasafe_default_values = self.\
            #     step_kw_inasafe_raster_default_values.\
            #     get_inasafe_default_values()
        else:
            inasafe_default_values.update(
                self.step_kw_default_inasafe_fields.get_inasafe_default_values(
                ))
            inasafe_default_values.update(
                self.step_kw_fields_mapping.get_field_mapping()['values'])

        if inasafe_default_values:
            keywords['inasafe_default_values'] = inasafe_default_values

        if self.step_kw_subcategory.selected_subcategory():
            subcategory = self.step_kw_subcategory.selected_subcategory()
            if subcategory.get('extra_keywords'):
                extra_keywords = self.step_kw_extra_keywords.\
                    get_extra_keywords()
                if extra_keywords:
                    keywords['extra_keywords'] = extra_keywords

        return keywords
432954
def search_keyword_top(self, category=None, count=20, period='today'):
        
        url = 'https://openapi.youku.com/v2/searches/keyword/top.json'
        params = {
            'client_id': self.client_id,
            'count': count,
            'period': period
        }
        if category:
            params['category'] = category
        r = requests.get(url, params=params)
        check_error(r)
        return r.json()
1111587
def get_categories(self, entry):
        
        try:
            return format_html_join(
                ', ', '<a href="{}" target="blank">{}</a>',
                [(category.get_absolute_url(), category.title)
                 for category in entry.categories.all()])
        except NoReverseMatch:
            return ', '.join([conditional_escape(category.title)
                              for category in entry.categories.all()])
476032
def search(self, keyword):
        ''''''
        if type(keyword) != unicode: q = keyword.decode('utf-8')
        req = self.fetch(self.search_url, {'q':q.encode('gbk')})
        if not req: return None
        html = req.content.decode('gbk').encode('utf-8')
        soup = BeautifulSoup(html, convertEntities=BeautifulSoup.HTML_ENTITIES, markupMassage=hexentityMassage)
        cats = self.cats_parser(soup)
        keywords = self.keywords_parser(soup)
        mall_items = self.mall_items_parser(soup)
        total = int(soup.find('div', attrs={'class':'user-easy'}).find('a').string)
        lists = self.lists_parser(soup)
        ads = self.ads_parser(soup)
        return SearchResults(keyword, total, lists, mall_items, ads, cats, keywords)
982050
public function getKeywords()
    {
        $dates = $this->getStartEndDate();

        $items = LaravelAnalytics::getTopKeyWordsForPeriod($dates['start'], $dates['end']);

        return $items;
    }
958246
def top_hits(hits, num, column, reverse):
    
    hits.sort(key = itemgetter(column), reverse = reverse)
    for hit in hits[0:num]:
        yield hit