@@ -0,0 +1,1644 @@
+import urllib, urllib2%0Aimport xml.etree.ElementTree as ET%0A%0Apubmed_search = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi'%0Apubmed_fetch = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi'%0A%0Adef send_request(url, data):%0A    try:%0A        req = urllib2.Request(url, data)%0A        res = urllib2.urlopen(req)%0A        xml_str = res.read()%0A        tree = ET.fromstring(xml_str)%0A    except:%0A        return None%0A    return tree%0A%0Adef get_ids(search_term, retmax=1000):%0A    params = %7B'db': 'pubmed',%0A                'term': search_term,%0A                'retstart': 0,%0A                'retmax': retmax%7D%0A    tree = send_request(pubmed_search, urllib.urlencode(params))%0A    if tree is None:%0A        return %5B%5D%0A    count = int(tree.find('Count').text)%0A    id_terms = tree.findall('IdList/Id')%0A    if id_terms is None:%0A        return %5B%5D%0A    ids = %5Bidt.text for idt in id_terms%5D%0A    if count != len(ids):%0A        print 'Not all ids were retreived, limited at %25d.' %25 retmax%0A    return ids%0A%0Adef get_abstract(pubmed_id):%0A    params = %7B'db': 'pubmed',%0A                'retmode': 'xml',%0A                'rettype': 'abstract',%0A                'id': pubmed_id%7D%0A    tree = send_request(pubmed_fetch, urllib.urlencode(params))%0A    if tree is None:%0A        return None%0A    article = tree.find('PubmedArticle/MedlineCitation/Article')%0A    if article is None:%0A        return None%0A    abstract = article.findall('Abstract/AbstractText')%0A    if abstract is None:%0A        return None%0A    else:%0A        abstract_text = ' '.join(%5B' ' if abst.text is None %0A                                    else abst.text for abst in abstract%5D)%0A        return abstract_text%0A

Add API for searching all PubMed abstracts and downloading the abstract text.