mirror of
https://git.pumpin.online/funkpower/catena.git
synced 2026-10-23 03:07:13 +00:00
bibfetch: ask every register that answers about a book, in turn
An ISBN is not a DOI. The body that assigns a DOI is the only one that has it, so one register is the whole answer. A book's identifier is assigned by its publisher and recorded by whoever gets round to it, and the record that comes back is as often as not missing the thing the caller wanted: asked about 9780199205592, OpenLibrary's edition record names *The First World War* and the press that printed it, and nobody at all as its author, because an edition record names its authors by key. So an ISBN now has a chain rather than a register. The edition record first, then OpenLibrary's own index — which answers with `author_name` filled in and costs nothing — and Google Books last, because it answers anonymous callers only until a daily quota runs out, after which it replies 429 to everyone behind the same address, as it is doing here today. The first complete answer wins, an incomplete one is kept in case nothing better comes, and a register being down is a failure only when every register is. `source` on the record says which one answered. colophon comes with it: the imprint reader was taking `Oxford is a registered trade mark of Oxford University Press` for a publisher and `Oxford N`, off `Oxford New York`, for a place. A legal notice mentioning a press is not the press, and a city is the city and not the first letter of the next one.
This commit is contained in:
@@ -86,20 +86,47 @@ fn main() -> ExitCode {
|
||||
}
|
||||
};
|
||||
|
||||
let Some(source) = Source::for_kind(&kind) else {
|
||||
let chain = Source::chain_for_kind(&kind);
|
||||
if chain.is_empty() {
|
||||
eprintln!("bibfetch: {id}: no register here answers about {kind} identifiers");
|
||||
missing += 1;
|
||||
continue;
|
||||
};
|
||||
}
|
||||
|
||||
match ask(&agent, source, &id, &kind, args.attempts) {
|
||||
Ok(record) => {
|
||||
// Ask the registers in turn and stop at the first complete answer.
|
||||
// An incomplete one is kept in case nothing better comes: a title
|
||||
// with no authors is still more than nothing, and a register being
|
||||
// down is only a failure when every register is.
|
||||
let mut best: Option<bibfetch::Record> = None;
|
||||
let mut last_error = None;
|
||||
for source in chain {
|
||||
match ask(&agent, *source, &id, &kind, args.attempts) {
|
||||
Ok(record) => {
|
||||
let complete =
|
||||
record.found && record.title.is_some() && !record.authors.is_empty();
|
||||
let better = best.as_ref().is_none_or(|kept| record.found && !kept.found);
|
||||
if complete {
|
||||
best = Some(record);
|
||||
break;
|
||||
}
|
||||
if better {
|
||||
best = Some(record);
|
||||
}
|
||||
}
|
||||
Err(why) => last_error = Some(why),
|
||||
}
|
||||
}
|
||||
|
||||
match best {
|
||||
Some(record) => {
|
||||
if !record.found {
|
||||
missing += 1;
|
||||
}
|
||||
records.push(record);
|
||||
}
|
||||
Err(why) => {
|
||||
None => {
|
||||
let why = last_error
|
||||
.map_or_else(|| "no register answered".to_string(), |e| e.to_string());
|
||||
eprintln!("bibfetch: {id}: {why}");
|
||||
return ExitCode::from(exit::UNAVAILABLE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user