-
Notifications
You must be signed in to change notification settings - Fork 6
/
zentralblatt.pl
executable file
·116 lines (100 loc) · 2.94 KB
/
zentralblatt.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/perl -w
# zentralblatt.PL - automates getting bibtex references from Zentralblatt
#
# Authors: Michael Tweedale <[email protected]>
# Gerd Wachsmuth <[email protected]>
# Version: 0.2
# Licence: GPL
use LWP::UserAgent;
use URI::URL;
use URI::Escape;
use Getopt::Long;
$mirror = "http://www.zbmath.org/";
$VERSION='0.2';
$search="?q=";
$sep = "";
$ua=new LWP::UserAgent;
$hdrs=new HTTP::Headers(Accept => 'text/html',
User_Agent => "zentralblatt.PL $VERSION");
sub version()
{
print STDERR << "EOF";
zentralblatt $VERSION
This is free software. You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.
Written by Michael Tweedale <m.tweedale\@bristol.ac.uk>,
Gerd Wachsmuth <gerd.wachsmuth\@mathematik.tu-chemnitz.de>.
EOF
}
sub usage()
{
print STDERR << "EOF";
Usage: $0 SEARCH...
Gets references from Zentralblatt in bibtex format.
-t, --title phrase from the title of the article or book
-a, --author name of one of the authors
-y, --year year of publication (ranges possible)
-s, --source source data (see zentralblatt)
--help display this help and exit
--version output version information and exit
Example 1: $0 -t "free+groups" -t trees -a bestvina -y 1997
Example 2: $0 -a serre -s annals -y 1955-
Example 3: $0 -a brown -s "graduate texts" -y -2000
EOF
}
sub addterm($$)
{
$search .= $sep . uri_escape($_[0]) . ":\"" . uri_escape($_[1]) . "\"";
$sep = " %26 ";
}
sub addyear($)
{
if( $_[0] =~ /-/ ) {
# A range of years is given.
@years = split(/-+/,$_[0]);
if( $#years == 0 )
{
$years[1] = "9999";
}
if( $years[0] =~ /^$/ )
{
$years[0] = "1000";
}
}
else {
# A single year is given.
$years[0] = $_[0];
$years[1] = $_[0];
}
$search .= $sep . "py:(" . $years[0] . "-" . $years[1] . ")";
$sep = " %26 ";
}
GetOptions('title|t=s' => sub { addterm("ti",$_[1]); },
'author|a=s' => sub { addterm("au",$_[1]); },
'source|s=s' => sub { addterm("so",$_[1]); },
'year|y=s' => sub { addyear($_[1]); },
'help|h' => sub { usage(); exit 0; },
'version|v' => sub { version(); exit 0; });
$search ne "search/?q=" || usage() && die("no search terms found");
$url=new URI::URL(
"$mirror$search");
$req=new HTTP::Request(GET, $url, $hdrs);
$resp=$ua->request($req);
$resp->is_success ||
print STDERR $resp->message . "\n" &&
die("failed to get search results from Zentralblatt");
$resp->as_string =~ /Your query produced no results/ &&
die("no results for this search");
map {
if (m{as BibTeX}) {
s/.*href="([^"]*\.bib)".*/$1/g;
$url=new URI::URL("$mirror$_");
$req=new HTTP::Request(GET, $url, $hdrs);
$resp=$ua->request($req);
$resp->is_success ||
print STDERR $resp->message . "\n" &&
die("failed to get search results from Zentralblatt");
print $resp->content . "\n\n";
}
} split "\n", $resp->as_string;