(self, query)
Search for a search term (max 10 results)
Search for a search term (max 10 results)
Search for a search term ( max 10 results )
def search(self, query):
        """
        Search for a search term (max 10 results)
        """
        # TODO: check that the query is valid
        sign = hmac.new(
            self.key.encode("utf-8"),
            query.encode("utf-8"),
            hashlib.sha256
        ).hexdigest()
        res = self._query("/search/%s&id=%s&sign=%s" % (query, self.user, sign))
        if res.status_code != 200:
            raise TotalHashError()
        else:
            root = ET.fromstring(res.text)
            result = root.find('result')
            res = {
                'total': int(result.attrib['numFound']),
                'results': [a.text for a in root.findall('.//result/doc/')]
            }
            return res
def search ( self , query ) : # TODO: check that the query is valid sign = hmac . new ( self . key . encode ( "utf-8" ) , query . encode ( "utf-8" ) , hashlib . sha256 ) . hexdigest ( ) res = self . _query ( "/search/%s&id=%s&sign=%s" % ( query , self . user , sign ) ) if res . status_code != 200 : raise TotalHashError ( ) else : root = ET . fromstring ( res . text ) result = root . find ( 'result' ) res = { 'total' : int ( result . attrib [ 'numFound' ] ) , 'results' : [ a . text for a in root . findall ( './/result/doc/' ) ] } return res