]> git.donarmstrong.com Git - bin.git/blobdiff - pubmed_search
use parallel xargs; fix up calls to perl to deal with escaping
[bin.git] / pubmed_search
index cc90661e363918f5a1e6cb3a5e8dffd78da9323e..23333ea3004257c94b48930759ecc996087c84ab 100755 (executable)
@@ -59,16 +59,18 @@ Display this manual.
 use vars qw($DEBUG);
 
 my %options = (debug           => 0,
-              help            => 0,
-              man             => 0,
-              color           => 1,
-              org_mode        => 0,
-              );
+               help            => 0,
+               man             => 0,
+               color           => 1,
+               org_mode        => 0,
+               abstract        => 1,
+              );
 
 GetOptions(\%options,
            'color|c!',
            'org_mode|org-mode',
            'pmid_only|pmid-only',
+           'abstract|a!',
            'debug|d+','help|h|?','man|m');
 
 pod2usage() if $options{help};
@@ -91,7 +93,14 @@ my $result = $fac->esearch(-email => 'don@donarmstrong.com',
                            -term => join(' ',@ARGV),
                            -retmax => 1000,
                           )->run();
+if ($result eq '0') {
+    print "No results\n";
+    exit;
+}
 my @ids = $result->ids;
+if (@ids > 0 and ref($ids[0])) {
+    @ids = @{$ids[0]};
+}
 if ($options{org_mode}) {
     print "* Pubmed search results for ".join(' ',@ARGV)." (".scalar(@ids).")\n";
     print "  + ";
@@ -107,11 +116,14 @@ my $raw_xml = $fac->efetch(-email => 'don@donarmstrong.com',
                           )->run(-raw_xml => 1);
 use XML::LibXML;
 my $xml = XML::LibXML->load_xml(string => $raw_xml);
-for my $article ($xml->findnodes('PubmedArticleSet/PubmedArticle/MedlineCitation')) {
-    # print $article->toString;
-    my ($pmid) = $article->findnodes('./PMID');
-    my ($title) = $article->findnodes('./Article/ArticleTitle');
-    my ($abstract) = $article->findnodes('./Article/Abstract');
+print STDERR $xml->toString if $DEBUG;
+for my $article ($xml->findnodes(q{//*[local-name()='MedlineCitation']})) {
+    print STDERR $article->toString if $DEBUG;
+    my ($pmid) = $article->findnodes(q{./*[local-name()='PMID']});
+    my ($title) = $article->findnodes(q{./*[local-name()='Article']}.
+                                      q{/*[local-name()='ArticleTitle']});
+    my ($abstract) = $article->findnodes(q{./*[local-name()='Article']}.
+                                         q{/*[local-name()='Abstract']});
     if ($options{org_mode}) {
         print "** PMID: ";
     }
@@ -122,8 +134,8 @@ for my $article ($xml->findnodes('PubmedArticleSet/PubmedArticle/MedlineCitation
     print BOLD CYAN if $options{color};
     print encode_utf8($title->textContent())."\n";
     print RESET if $options{color};
-    print BOLD MAGENTA if $options{color};
-    if (defined $abstract) {
+    if (defined $abstract and $options{abstract}) {
+        print BOLD MAGENTA if $options{color};
         if ($options{org_mode}) {
             print "*** Abstract\n";
         }