X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=pubmed_search;h=c0d15ce50afb745f3fb2a6f3b781a21e131dacaf;hb=1886c7247cb16ed68a78cd5550b152689a465999;hp=6dff865533161e8f40eadd9daed9d1fc5b755d68;hpb=0260e5793d19fff40feba13d42dfe1315cdaa88f;p=bin.git diff --git a/pubmed_search b/pubmed_search index 6dff865..c0d15ce 100755 --- a/pubmed_search +++ b/pubmed_search @@ -12,7 +12,7 @@ use strict; use Getopt::Long; use Pod::Usage; -use Bio::DB::SoapEUtilities; +use Bio::DB::EUtilities; use Encode qw(encode_utf8); use Term::ANSIColor qw(:constants); @@ -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}; @@ -84,14 +86,23 @@ if (not @ARGV) { pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS; -my $fac = Bio::DB::SoapEUtilities->new(); - -my $result = $fac->esearch(-email => 'don@donarmstrong.com', - -db => 'pubmed', - -term => join(' ',@ARGV), - -retmax => 1000, - )->run(); -my @ids = $result->ids; +my $result = + Bio::DB::EUtilities->new(-email => 'don@donarmstrong.com', + -db => 'pubmed', + -term => join(' ',@ARGV), + -retmax => 1000, + -eutil => 'esearch', + ); +my @ids; +eval { + # this warns for everything, so hide the warning. + local $SIG{__WARN__} = sub {}; + @ids = $result->get_ids('pubmed') +}; +if (not @ids) { + print "No results\n"; + exit; +} if (@ids > 0 and ref($ids[0])) { @ids = @{$ids[0]}; } @@ -104,17 +115,21 @@ if ($options{org_mode}) { } print scalar(@ids)." results:\n"; exit 0 unless @ids; -my $raw_xml = $fac->efetch(-email => 'don@donarmstrong.com', - -db => 'pubmed', - -id => \@ids - )->run(-raw_xml => 1); +my $raw_xml = Bio::DB::EUtilities->new(-email => 'don@donarmstrong.com', + -db => 'pubmed', + -id => \@ids, + -eutil => 'efetch', + ); 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'); +my $xml = XML::LibXML->load_xml(string => $raw_xml->get_Response->content); +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: "; } @@ -125,8 +140,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"; }