<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import httplib
#import xml.dom.minidom as minidom
#import urllib
import time, sys
import xml.etree.ElementTree as ET

def get_pubmed_abs(pmid):
    conn = httplib.HTTPConnection("eutils.ncbi.nlm.nih.gov")
    conn.request("GET", '/entrez/eutils/efetch.fcgi?db=pubmed&id=%s&retmode=xml&rettype=xml' % pmid)
    r1 = conn.getresponse()
    #print "Request Status: " + str(r1.status) + " " + str(r1.reason)
    response = r1.read()
    #print response[3]
    abstract = parse_pubmed_xml(response)
    return abstract, str(r1.status) + ' ' + str(r1.reason)

    
def parse_pubmed_xml(xml):
    #print xml
    if xml.strip() == '':
        print "PMID not found"
        sys.exit()
    else:
        root = ET.fromstring(xml)
        abstext = root.findall('.//AbstractText')
        if len(abstext) > 0:
            abstext = abstext[0].text
        else:
            print "Abstract not found"
            sys.exit()
    return abstext
    
    
    
def main():
    print get_pubmed_abs(sys.argv[1])
    
if __name__ == "__main__":
    main()
    <commit_msg>Return Pubmed title and abstract<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import httplib
#import xml.dom.minidom as minidom
#import urllib
import time, sys
import xml.etree.ElementTree as ET

def get_pubmed_abs(pmid):
    conn = httplib.HTTPConnection("eutils.ncbi.nlm.nih.gov")
    conn.request("GET", '/entrez/eutils/efetch.fcgi?db=pubmed&id=%s&retmode=xml&rettype=xml' % pmid)
    r1 = conn.getresponse()
    #print "Request Status: " + str(r1.status) + " " + str(r1.reason)
    response = r1.read()
    # print response
    title, abstract = parse_pubmed_xml(response)
    return title, abstract, str(r1.status) + ' ' + str(r1.reason)

    
def parse_pubmed_xml(xml):
    #print xml
    if xml.strip() == '':
        print "PMID not found"
        sys.exit()
    else:
        root = ET.fromstring(xml)
        title = root.findall('.//ArticleTitle').text
        abstext = root.findall('.//AbstractText')
        if len(abstext) > 0:
            abstext = abstext[0].text
        else:
            print "Abstract not found"
            sys.exit()
    return title, abstext
    
    
    
def main():
    print get_pubmed_abs(sys.argv[1])
    
if __name__ == "__main__":
    main()
    
{'fraction_non_alphanumeric': 0.14138375590889557, 'fraction_numerical': 0.009024495058014611, 'mean_word_length': 2.565084226646248, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 20}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7435271', 'n_tokens_mistral': 840, 'n_tokens_neox': 824, 'n_words': 169}