getCite.pl untested

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 101 CC 5 SCAR 27.7
CC
5
Cov
0%
print_bibtex_citation
30.0
BEGIN
2.0
BEGIN
2.0
CRAP 16.0
1 #!/usr/bin/perl
2 #
3 # getCite.pl by Vincent LaBella vlabella@uark.edu
4 #
5 use LWP::Simple;
6 use Text::ParseWords;
7 use INSPEC::Retriever;
8 use INSPEC::BibTeX;
9
10 my $program = "getCite";
11 my $filedate="1/30/2001";
12 my $fileversion="1.0 R0.1";
13 my $copyright = "Copyright 2001 by Vincent P. LaBella";
14 my $title = "\U$program\E $fileversion, $filedate - $copyright\n";
15
16 ### options
17 $::opt_dump=0;
18 $::opt_noprescan=0;
19 $::opt_debug=0;
20 $::opt_bibfile=STDOUT;
21
22 #
23 # adjust these package globals for your site
24 #
25 $INSPEC::Retriever::AXIOM_userid = "getcite" ; # default username
26 $INSPEC::Retriever::AXIOM_password = "getcite1"; # default password, you may want to make your own
27 $INSPEC::Retriever::AXIOM_code = "ARKAN" ; # for the University of Arkansas
28
29
30 ### usage
31 my @bool = ("false", "true");
32 my $usage = <<"END_OF_USAGE";
33 ${title}Syntax: $program <CODEN or ISSN> <Volume> <Starting Page Number> [options]
34 ---------------------------------------------------------------------------
35 Options:
36 --help: print usage
37 --bib file append entry to "file" (defualt: $::opt_bibfile)
38 will search BIBINPUTS dirs too
39 --(no)debug: debug information (default: $bool[$::opt_debug])
40 --(no)dump: Dump HTML output to page1.html page2.html page3.html url
41 (default: $bool[$::opt_dump])
42 --noprescan Omit prescanning of the database (default: $bool[$::opt_prescan])
43
44 Examples for getting Phys. Rev. Lett. Volume 83 Page 2989 into mycite.bib
45 * $program PRLTAO 83 2989 --bib mycite
46 or
47 * $program PRLTAO 83 2989 --bib mycite.bib
48 or (using ISSN)
49 * $program 0031-9007 83 2989 --bib mycite
50 or
51 * $program 0031-9007 83 2989 --bib mycite.bib
52 END_OF_USAGE
53
54 sub print_bibtex_citation
55 {
56 # takes a bibtex entry hash and
57 # returns it in a single string with no newline characters
58 # for output to a file or whatever
59 # opposite of parse_bibtex_citation
60 # append keys not to be enclosed in {}
61 my ($ret,$i,$key) = "";
62 my ($cite) = @_;
63
64 my %omits;
65 if( @_ > 1 ){
66 for( $i=1;$i<@_;$i++)
67 {
68 if(@_[$i] ne "")
69 {
70 $omits{@_[$i]}=1;
71 }
72 }
73 }
74
75 $ret = "\@".$cite->{"type"}."{".$cite->{"key"}.",\n";
76
77 foreach $key (keys %$cite)
78 {
79 if($key ne "key" && $key ne "type")
80 {
81 if( exists $omits{$key})
82 {
83 $ret.=$key."=".$cite->{$key}.",\n";
84 }
85 else
86 {
87 $ret.=$key."={".$cite->{$key}."},\n";
88 }
89 }
90 }
91 $ret =~ s/,$/}/;
92 return $ret;
93 }
94
95
96 ### process options
97 use Getopt::Long;
98 GetOptions (
99 "help!",
100 "debug!",
101 "dump!",
102 "noprescan!",
103 "bib=s" => \$::opt_bibfile,
104 ) or die $usage;
105
106 ### option help
107 die $usage if $::opt_help;
108 die $usage if @ARGV == 0 ;
109
110 my ($journal,$volume,$page) = @ARGV;
111 print "Looking up ==> $journal, Vol: $volume, Page: $page Please Wait..";
112
113 %entry = INSPEC::Retriever::retrieve($journal,$volume,$page);
114
115 if(! (exists $entry{'ERROR'}) )
116 {
117 print "Done\n";
118 %bibtexentry = INSPEC::BibTeX::Inspec_to_BibTeX(\%entry);
119 if($::opt_bibfile eq "STDOUT")
120 {
121 print print_bibtex_citation(\%bibtexentry,"key","type")."\n";
122 }
123 elsif($::opt_bibfile ne "")
124 {
125 open(fh,">>".$::opt_bibfile);
126 print fh print_bibtex_citation(\%bibtexentry,"key","type")."\n";
127 close(fh);
128 }
129 else
130 {
131 print "ERROR cant open $::opt_bibfile\n";
132 }
133 }
134 else
135 {
136 print "ERROR!!\n";
137 print "Couldn't find the citation in INSPEC databse]--!!\n";
138 print "Reasons:\n(1) The citation is too old (i.e older than 1968).\n";
139 print "(2) The journal [".$jname."] is not contained in the INSPEC database.\n";
140 print "(3) The volume[".$volume."], page number[".$page."], and journal code[".$journal."] were incorrectly specified.\n";
141 print "(4) The AXION INPSEC server is down or too busy. Goto axiom.iop.org/S/ARKAN/search and try a manual search to see.\n";
142 }