Ejemplo n.º 1
0
    def _get_completions(self, data):
        cs = []

        root = fromstring(data)

        headings = root.findall("div")[1:-1]

        for h in headings:
            title = h.find("p").text
            listE = h.getnext()

            if listE.tag == 'ul':

                if "Categor" in title:
                    req_type = FarnellSearch.R_CATEGORY
                elif "Manufactur" in title:
                    req_type = FarnellSearch.R_MANUFACTURER
                else:
                    # what is this heading? something new and exciting, no
                    # doubt
                    # some way to flag possible new things needed?
                    continue

                for a in listE.findall(".//a"):

                    url = a.get('href')
                    name = a.xpath("string()").strip()

                    try:
                        desc, name = name.rsplit(" > ", 1)
                    except ValueError:
                        desc = None

                    cs.append(
                        mnemory.CompletionResult(name,
                                                 url=url,
                                                 category=title,
                                                 description=desc,
                                                 req_type=req_type))

            else:  # this is a product table
                for tr in listE.findall(".//tr"):
                    left = tr.find("td[@id='leftcolumn']/a")

                    url = left.get("href")
                    name = left.xpath("string()").strip()

                    desc = tr.find("td[@id='contentwrapper']/a").xpath(
                        "string()").strip()

                    cs.append(
                        mnemory.CompletionResult(
                            name,
                            url=url,
                            category=title,
                            description=desc,
                            req_type=FarnellSearch.R_PRODUCT))

        return cs
Ejemplo n.º 2
0
    def _get_completions(self, data):

        data = loads(data)

        cs = [mnemory.CompletionResult(c['input']) for c in data['results']]

        return cs
Ejemplo n.º 3
0
 def parse(x):
     symbol = x['t']
     name = x['n']
     exchange = x['e']
     return mnemory.CompletionResult(symbol,
                                     description="%s - %s" %
                                     (name, exchange))
Ejemplo n.º 4
0
    def _get_completions(self, data):
        data = loads(data)

        # the basic completions - not the "node" results
        simple_compls = data[1]

        compls = [mnemory.CompletionResult(x) for x in simple_compls]
        return compls
Ejemplo n.º 5
0
    def _get_completions(self, data):

        # ugh, no quotes in the "JSON", just load the array
        result = data_utils.stringLongestBetween(data, "[", "]", True)
        result = json.loads(result)

        cs = [mnemory.CompletionResult(c) for c in result]
        return cs
Ejemplo n.º 6
0
    def _get_completions(self, data):

        result = data_utils.stripJsonp(data)

        t = json.loads(result)

        cs = [mnemory.CompletionResult(c) for c in t['s']]
        return cs
Ejemplo n.º 7
0
    def _get_completions(self, result):

        result = data_utils.stripJsonp(result)
        result = json.loads(result)

        cs = [mnemory.CompletionResult(c) for c in result['res']['sug']]

        return cs
Ejemplo n.º 8
0
    def _get_completions(self, data):

        cs = []

        # this is pretty ugly but it gets us the right results
        for r in data.split("this.txtBox.value%3D")[1:]:
            quoted = r.split("%22", 1)[0]
            kw = unquote(quoted)
            cs.append(kw)

        cs = [mnemory.CompletionResult(c) for c in cs]
        return cs
Ejemplo n.º 9
0
        def parse(typ, cs):
            res = []
            for c in cs:
                if typ == "query":
                    url = None  # use the req url
                elif typ == "part" or typ == "brand":
                    url = self.base + c['octopart_url']
                elif typ == "category":
                    args = ["category_uids", c['uid']]

                    url = (
                        "https://octopart.com/search?filter%5Bfields%5D%5B" +
                        args[0] + "%5D%5B%5D=" + args[1])

                res.append(
                    mnemory.CompletionResult(c['text'], url=url, category=typ))
            return res
Ejemplo n.º 10
0
    def _get_completions(self, data):

        data = loads(data)

        cs = [mnemory.CompletionResult(x) for x in data[1]]
        return cs
Ejemplo n.º 11
0
        def parse(entry):

            kwd, uid = entry['value'].split("##", 1)

            return mnemory.CompletionResult(kwd.strip(), url=uidUrl % uid)
Ejemplo n.º 12
0
 def process(res):
     res = html.unescape(res.replace("<b>", "").replace("</b>", ""))
     return mnemory.CompletionResult(res)
Ejemplo n.º 13
0
    def _get_completions(self, data):

        data = self.stripJsonp(data)
        result = loads(data)

        return [mnemory.CompletionResult(c[0]) for c in result[1]]
Ejemplo n.º 14
0
 def parseResult(e):
     res = mnemory.CompletionResult(e['title'],
                                    category=e['type'],
                                    url=self.getRequestUrl(e['mid']))
     return res
Ejemplo n.º 15
0
 def process(keyword):
     c = mnemory.CompletionResult(keyword)
     return c
Ejemplo n.º 16
0
    def _get_completions(self, data):

        data = loads(data)
        keys = [s['value'] for s in data]

        return [mnemory.CompletionResult(key) for key in keys]