]> git.donarmstrong.com Git - bin.git/blobdiff - pubmed_search
ignore habits in ical export
[bin.git] / pubmed_search
index 7b3041ed43b4f552bebb1082e9b2c185e8a6910b..778960a7f187db49f5eaa4c8d8934a6d8bcb1cec 100755 (executable)
@@ -12,7 +12,7 @@ use strict;
 use Getopt::Long;
 use Pod::Usage;
 
-use Bio::DB::EUtilities;
+use Bio::DB::SoapEUtilities;
 
 use Encode qw(encode_utf8);
 use Term::ANSIColor qw(:constants);
@@ -84,13 +84,17 @@ if (not @ARGV) {
 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
 
 
-my $search = Bio::DB::EUtilities->new(-eutil => 'esearch',
-                                      -email => 'don@donarmstrong.com',
-                                      -db    => 'pubmed',
-                                      -term => join(' ',@ARGV),
-                                      -retmax => 1000,
-                                     );
-my @ids = $search->get_ids();
+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;
+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 "  + ";
@@ -100,18 +104,20 @@ if ($options{org_mode}) {
 }
 print scalar(@ids)." results:\n";
 exit 0 unless @ids;
-my $esummary = Bio::DB::EUtilities->new(-eutil => 'efetch',
-                                        -email => 'don@donarmstrong.com',
-                                        -db    => 'pubmed',
-                                        -id  => \@ids
-                                       );
+my $raw_xml = $fac->efetch(-email => 'don@donarmstrong.com',
+                           -db    => 'pubmed',
+                           -id  => \@ids
+                          )->run(-raw_xml => 1);
 use XML::LibXML;
-my $xml = XML::LibXML->load_xml(string => $esummary->get_Response()->content());
-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);
+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: ";
     }