Beispiel #1
0
def get_hit_count_or_raise(term, db='pubmed', **kwargs):
    """Call eSearch_query and performs error checking.
   Raise Exceptions if no hit, or PubMed errors, otherwise
   return hit count."""

    # Call 'eSearch_query()' and parse the output.
    query = {}
    parser = make_parser()
    parser.setContentHandler(eSearchResultHandler(query))
    parser.parse(
        eSearch_query(
            term=term,
            db=db,
            usehistory=False,
            retmax=0,  # (do not return any hit).
            **kwargs))

    # Check for the presence of "ErrorList".
    if query.get('errors'):
        raise PubMedException(query.get('errors'))

    # Check hit count.
    # NB: in case PubMed issues a 'PhraseNotFound' error
    # there will be no hit, but the command above will
    # have fired a PubMedException before we get here.
    count = int(query.get('count', 0))
    if count == 0:
        raise NoHitException(term)
    else:
        return count
Beispiel #2
0
def get_hit_count(term, **kwargs):
   """Call eSearch_query and performs error checking.
   Raise Exceptions if no hit, or PubMed errors, otherwise
   return hit count."""

   # Call 'eSearch_query()' and parse the output.
   query = {}
   parser = make_parser()
   parser.setContentHandler(eSearchResultHandler(query))
   parser.parse(eSearch_query(
         term = term,
         usehistory = False,
         retmax = 0, # (do not return any hit).
         **kwargs
      ))

   # Check for the presence of "ErrorList".
   if query.get('errors'):
      raise PubMedException(query.get('errors'))

   # Check hit count.
   # NB: in case PubMed issues a 'PhraseNotFound' error
   # there will be no hit, but the command above will
   # have fired a PubMedException before we get here.
   count = int(query.get('count', 0))
   if count == 0:
      raise NoHitException(term)
   else:
      return count
Beispiel #3
0
def fetch_XML(term, db='pubmed', **kwargs):
    """Query PubMed and return an XML stream."""

    eFetch_params = kwargs
    parser = make_parser()
    parser.setContentHandler(eSearchResultHandler(eFetch_params))
    parser.parse(robust_eSearch_query(term, db, **kwargs))

    # Plug-in the results of eSearch in eFetch.
    return eFetch_query(db=db, **eFetch_params)
Beispiel #4
0
def fetch_XML(term, **kwargs):
   """Query PubMed and return an XML stream."""

   eFetch_params = kwargs
   parser = make_parser()
   parser.setContentHandler(eSearchResultHandler(eFetch_params))
   parser.parse(robust_eSearch_query(term, **kwargs))

   # Plug-in the results of eSearch in eFetch.
   return eFetch_query(**eFetch_params)