source: products/qSEOptimizer/trunk/adapters.py

Last change on this file was 1, checked in by myroslav, 18 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 1.5 KB
RevLine 
[1]1import re, commands
2from zope.interface import implements
3from Products.CMFCore.utils import getToolByName
4from Products.qSEOptimizer.interfaces import IKeywords
5
6
7class AdditionalKeywords(object):
8    implements(IKeywords)
9
10    def __init__(self, context):
11        self.context = context
12
13    def listKeywords(self):
14        portal_props = getToolByName(self.context, 'portal_properties')
15        seo_props = getToolByName(portal_props, 'seo_properties')
16
17        # now set type is not using because of it unordered behaviour
18        #original = set(self.context.qSEO_Keywords())
19        #additional = set(seo_props.additional_keywords)
20        #text = set(self.context.SearchableText().split())
21        #keywords = list(additional.intersection(text).union(original))
22
23        keywords = list(self.context.qSEO_Keywords())
24        lower_keywords = map(lambda x: x.lower(), keywords)
25        additional = seo_props.additional_keywords
26
27        is_test = self.context.REQUEST.get('qseo_without_additional_keywords', None)
28
29        if additional and is_test is None:
30            # extract words from url page using lynx browser
31            text = commands.getoutput('lynx --dump --nolist %s?qseo_without_additional_keywords=1' % self.context.absolute_url()).lower()
32            if text and text != 'sh: lynx: command not found':
33                for keyword in additional:
34                    if keyword.lower() not in lower_keywords and re.compile(r'\b%s\b' % keyword, re.I).search(text):
35                        keywords.append(keyword)
36
37        return ', '.join(keywords)
Note: See TracBrowser for help on using the repository browser.