]> git.donarmstrong.com Git - bin.git/commitdiff
output org mode
authorDon Armstrong <don@donarmstrong.com>
Wed, 10 Oct 2012 21:33:42 +0000 (21:33 +0000)
committerDon Armstrong <don@donarmstrong.com>
Wed, 10 Oct 2012 21:33:42 +0000 (21:33 +0000)
pubmed_search

index b5272e32005b5de7df5a37b260b9987901972532..b3367d934497f13391a79cbadb62391aaabc9d05 100755 (executable)
@@ -61,9 +61,13 @@ use vars qw($DEBUG);
 my %options = (debug           => 0,
               help            => 0,
               man             => 0,
+              color           => 1,
+              org_mode        => 0,
               );
 
 GetOptions(\%options,
+          'color|c!',
+          'org_mode|org-mode',
           'debug|d+','help|h|?','man|m');
 
 pod2usage() if $options{help};
@@ -86,7 +90,12 @@ my $search = Bio::DB::EUtilities->new(-eutil => 'esearch',
                                       -retmax => 1000,
                                      );
 my @ids = $search->get_ids();
+if ($options{org_mode}) {
+    print "* Pubmed search results for ".join(' ',@ARGV)." (".scalar(@ids).")\n";
+    print "  + ";
+}
 print scalar(@ids)." results:\n";
+exit 0 unless @ids;
 my $esummary = Bio::DB::EUtilities->new(-eutil => 'efetch',
                                        -email => 'don@donarmstrong.com',
                                        -db    => 'pubmed',
@@ -99,21 +108,29 @@ for my $article ($xml->findnodes('PubmedArticleSet/PubmedArticle/MedlineCitation
     my ($pmid) = $article->findnodes('./PMID');
     my ($title) = $article->findnodes('./Article/ArticleTitle');
     my ($abstract) = $article->findnodes('./Article/Abstract');
-    print BOLD GREEN;
+    if ($options{org_mode}) {
+       print "** PMID: ";
+    }
+    print BOLD GREEN if $options{color};
     print $pmid->textContent();
     print ": ";
-    print RESET;
-    print BOLD CYAN;
-    print $title->textContent()."\n";
-    print RESET;
-    print BOLD MAGENTA;
-    $abstract = $abstract->textContent();
-    $abstract =~ s/^\s*//mg;
-    $abstract =~ s/(.{,80})\s/$1\n/g;
-    $abstract = encode_utf8($abstract);
-    print wrap('','',$abstract);
-    print "\n\n";
-    print RESET;
+    print RESET if $options{color};
+    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 ($options{org_mode}) {
+           print "*** Abstract\n";
+       }
+       $abstract = $abstract->textContent();
+       $abstract =~ s/^\s*//mg;
+       $abstract =~ s/(.{,80})\s/$1\n/g;
+       $abstract = encode_utf8($abstract);
+       print wrap('','',$abstract);
+       print "\n\n";
+       print RESET if $options{color};
+    }
 }
 
 __END__