示例#1
0
    def get_article_by_search_wap(keyword, wap_dict):
        datas = []
        for i in wap_dict['items']:
            item = str_to_bytes(i).replace(
                b'\xee\x90\x8a' + str_to_bytes(keyword) + b'\xee\x90\x8b',
                str_to_bytes(keyword))
            root = XML(item)
            display = root.find('.//display')
            datas.append({
                'gzh': {
                    'profile_url': display.find('encGzhUrl').text,
                    'open_id': display.find('openid').text,
                    'isv': display.find('isV').text,
                    'wechat_name': display.find('sourcename').text,
                    'wechat_id': display.find('username').text,
                    'headimage': display.find('headimage').text,
                    'qrcode': display.find('encQrcodeUrl').text,
                },
                'article': {
                    'title': display.find('title').text,
                    'url': display.find('url').text,  # encArticleUrl
                    'main_img': display.find('imglink').text,
                    'abstract': display.find('content168').text,
                    'time': display.find('lastModified').text,
                },
            })

        return datas
示例#2
0
 def getVersion(self, currentTag):
     url = self.URL
     update = urlopen(url).read()
     root = XML(update)
     cur_version = root.find(".//" + currentTag)
     current = cur_version.text
     return current
示例#3
0
 def getMessage(self, messageTag):
     url = self.URL
     update = urlopen(url).read()
     root = XML(update)
     mess = root.find(".//" + messageTag)
     message = mess.text
     return message
示例#4
0
    def get_article_by_search_wap(keyword, wap_dict):
        datas = []
        for i in wap_dict['items']:
            item = str_to_bytes(i).replace(b'\xee\x90\x8a' + str_to_bytes(keyword) + b'\xee\x90\x8b',
                                           str_to_bytes(keyword))
            root = XML(item)
            display = root.find('.//display')
            datas.append({
                'gzh': {
                    'profile_url': display.find('encGzhUrl').text,
                    'open_id': display.find('openid').text,
                    'isv': display.find('isV').text,
                    'wechat_name': display.find('sourcename').text,
                    'wechat_id': display.find('username').text,
                    'headimage': display.find('headimage').text,
                    'qrcode': display.find('encQrcodeUrl').text,
                },
                'article': {
                    'title': display.find('title').text,
                    'url': display.find('url').text,  # encArticleUrl
                    'main_img': display.find('imglink').text,
                    'abstract': display.find('content168').text,
                    'time': display.find('lastModified').text,
                },
            })

        return datas
示例#5
0
def do_search(param, sort, page=1, rows=100):
    (reply, solr_select, q_list) = run_solr_query(param, rows, page, sort)
    is_bad = False
    if reply.startswith('<html'):
        is_bad = True
    if not is_bad:
        try:
            root = XML(reply)
        except XMLSyntaxError:
            is_bad = True
    if is_bad:
        m = re_pre.search(reply)
        return web.storage(
            facet_counts = None,
            docs = [],
            is_advanced = bool(param.get('q', 'None')),
            num_found = None,
            solr_select = solr_select,
            q_list = q_list,
            error = (web.htmlunquote(m.group(1)) if m else reply),
        )

    docs = root.find('result')
    return web.storage(
        facet_counts = read_facets(root),
        docs = docs,
        is_advanced = bool(param.get('q', 'None')),
        num_found = (int(docs.attrib['numFound']) if docs is not None else None),
        solr_select = solr_select,
        q_list = q_list,
        error = None,
    )
示例#6
0
def do_search(param, sort, page=1, rows=100, spellcheck_count=None):
    if sort:
        sort = process_sort(sort)
    (solr_result, solr_select, q_list) = run_solr_query(
        param, rows, page, sort, spellcheck_count
    )
    is_bad = False
    if not solr_result or solr_result.startswith(b'<html'):
        is_bad = True
    if not is_bad:
        try:
            root = XML(solr_result)
        except XMLSyntaxError:
            is_bad = True
    if is_bad:
        m = re_pre.search(solr_result)
        return web.storage(
            facet_counts=None,
            docs=[],
            is_advanced=bool(param.get('q')),
            num_found=None,
            solr_select=solr_select,
            q_list=q_list,
            error=(web.htmlunquote(m.group(1)) if m else solr_result),
        )

    spellcheck = root.find("lst[@name='spellcheck']")
    spell_map = {}
    if spellcheck is not None and len(spellcheck):
        for e in spellcheck.find("lst[@name='suggestions']"):
            assert e.tag == 'lst'
            a = e.attrib['name']
            if a in spell_map or a in ('sqrt', 'edition_count'):
                continue
            spell_map[a] = [i.text for i in e.find("arr[@name='suggestion']")]

    docs = root.find('result')
    return web.storage(
        facet_counts=read_facets(root),
        docs=docs,
        is_advanced=bool(param.get('q')),
        num_found=(int(docs.attrib['numFound']) if docs is not None else None),
        solr_select=solr_select,
        q_list=q_list,
        error=None,
        spellcheck=spell_map,
    )
示例#7
0
def do_search(param, sort, page=1, rows=100, spellcheck_count=None):
    (reply, solr_select, q_list) = run_solr_query(
        param, rows, page, sort, spellcheck_count)
    is_bad = False
    if not reply or reply.startswith('<html'):
        is_bad = True
    if not is_bad:
        try:
            root = XML(reply)
        except XMLSyntaxError:
            is_bad = True
    if is_bad:
        m = re_pre.search(reply)
        return web.storage(
            facet_counts = None,
            docs = [],
            is_advanced = bool(param.get('q')),
            num_found = None,
            solr_select = solr_select,
            q_list = q_list,
            error = (web.htmlunquote(m.group(1)) if m else reply),
        )

    spellcheck = root.find("lst[@name='spellcheck']")
    spell_map = {}
    if spellcheck is not None and len(spellcheck):
        for e in spellcheck.find("lst[@name='suggestions']"):
            assert e.tag == 'lst'
            a = e.attrib['name']
            if a in spell_map or a in ('sqrt', 'edition_count'):
                continue
            spell_map[a] = [i.text for i in e.find("arr[@name='suggestion']")]

    docs = root.find('result')
    return web.storage(
        facet_counts = read_facets(root),
        docs = docs,
        is_advanced = bool(param.get('q')),
        num_found = (int(docs.attrib['numFound']) if docs is not None else None),
        solr_select = solr_select,
        q_list = q_list,
        error = None,
        spellcheck = spell_map,
    )
示例#8
0
文件: ttmg.py 项目: vietrap91/remote
      def getMessage(self, messageTag):
          from urllib.request import urlopen
          from lxml.etree import XML

          url = self.URL
          update = urlopen(url).read()
          root = XML(update)
          mess = root.find(".//"+messageTag)
          message = mess.text
          return message
示例#9
0
文件: ttmg.py 项目: vietrap91/remote
      def getVersion(self, currentTag):
          from urllib.request import urlopen
          from lxml.etree import XML

          url = self.URL
          update = urlopen(url).read()
          root = XML(update)
          cur_version = root.find(".//"+currentTag)
          current = cur_version.text
          return current
示例#10
0
def parse_error(xml_str):
    error = {}
    doc = XML(xml_str)
    if doc.tag == 'error':
        elem = doc
    elif doc.tag == 'customers':
        elem = doc.find('.//error')
    else:
        raise Exception("Can't find error element in '%s'" % xml_str)
    client_log.debug(elem)
    error['id'] = elem.attrib['id']
    error['code'] = elem.attrib['code']
    error['aux_code'] = elem.attrib['auxCode']
    error['message'] = elem.text

    return error
示例#11
0
def parse_error(xml_str):
    error = {}
    doc = XML(xml_str)
    if doc.tag == 'error':
        elem = doc
    elif doc.tag == 'customers':
        elem = doc.find('.//error')
    else:
        raise Exception("Can't find error element in '%s'" % xml_str)
    client_log.debug(elem)
    error['id'] = elem.attrib['id']
    error['code'] = elem.attrib['code']
    error['aux_code'] = elem.attrib['auxCode']
    error['message'] = elem.text
    
    return error
示例#12
0
def parse_error(xml_str):
    error = {}
    doc = XML(xml_str)
    if doc.tag == "error":
        elem = doc
    elif doc.tag == "customers":
        elem = doc.find(".//error")
    else:
        raise Exception("Can't find error element in '%s'" % xml_str)
    client_log.debug(elem)
    error["id"] = elem.attrib["id"]
    error["code"] = elem.attrib["code"]
    error["aux_code"] = elem.attrib["auxCode"]
    error["message"] = elem.text

    return error