-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a tool that maps authors to libris IDs based on hand-reviewed log…
… files from tools/author-libris-id.pl
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use 5.010; | ||
use strict; | ||
use warnings; | ||
use lib 'lib'; | ||
use Quelology::Config qw/schema/; | ||
use WebService::Libris; | ||
use Mojo::URL; | ||
binmode STDOUT, ':encoding(UTF-8)'; | ||
binmode ARGS, ':encoding(UTF-8)'; | ||
$| = 1; | ||
|
||
my $schema = schema; | ||
while (<>) { | ||
chomp; | ||
next unless s/^REVIEW:\s*//; | ||
my ($id, $libris_id) = split; | ||
my $l = WebService::Libris->new(type => 'auth', id => $libris_id); | ||
my $a = $schema->a->by_id($id); | ||
eval { | ||
$schema->txn_do( sub { | ||
$a->update({ libris_id => $l->id }); | ||
$a->create_related('links', { | ||
type => 'libris', | ||
lang => 'en', | ||
url => "http://libris.kb.se/auth/" . $l->id, | ||
}); | ||
my $same_as = $l->same_as; | ||
if ($same_as) { | ||
my $mu = Mojo::URL->new($same_as); | ||
my $type = (split /\./, $mu->host)[-2]; | ||
say " $type: $same_as"; | ||
$a->create_related('links', { | ||
type => $type, | ||
lang => 'en', | ||
url => $same_as, | ||
}); | ||
} | ||
}); | ||
}; | ||
warn $@ if $@; | ||
} |