Documentation
¶
Overview ¶
Package arxiv finds papers on arXiv by their ids and names their PDFs as products to fetch, gently.
Every request, to the API and for a PDF, goes through one Gate: one at a time, three seconds apart at least, as arXiv's API terms ask. When arXiv answers 403, 429 or 503 it is asking us to stop, and nothing more is asked.
A gate held through a record keeps the pace, and any wait arXiv asked for, from one run to the next.
The API is asked through github.com/Epistemic-Technology/arxiv. Its v1.0.1 paces by three nanoseconds, replaces a limiter it is given, and parses a 429 as results; so its pacing is turned off, the Gate paces instead, and the answer's status is read here before it is.
Index ¶
Constants ¶
const API = "https://export.arxiv.org/api/query"
API is the address of arXiv's API on export.arxiv.org, the host arXiv sets aside for programs.
Variables ¶
This section is empty.
Functions ¶
func AskedToStop ¶
AskedToStop is whether an error is arXiv asking us to stop: a 403, 429 or 503 from the API or a PDF fetched through a paced web, or a wait arXiv asked for that has not passed.
func Paced ¶
Paced is a web whose every request goes through the gate, waiting there while ctx lasts. One goes at a time, each begun at least the gate's pace after the last began. A Get holds the gate until its body is closed, so a slow download is still the only request.
It refuses a missing context, web or gate.
Types ¶
type Clock ¶
Clock is the time a gate keeps. Its Sleep ends early when the context ends, and gives the context's error.
type Gate ¶
type Gate struct {
// contains filtered or unexported fields
}
Gate lets one request at a time through to arXiv. Each starts at least its pace after the one before started. A request enters, is answered and leaves; the next waits at the gate.
Held, a gate keeps its last start and any time arXiv asked it to wait until in a record, so the pace and the wait carry over between runs.
func NewGate ¶
NewGate is a gate at a pace, on a clock. It refuses a pace quicker than arXiv's least, so a mistake in a numbers file cannot ask faster than arXiv allows. It refuses a missing clock too.
func (*Gate) Asked ¶
Asked is how many requests the gate has let through. Read it when none is waiting.
func (*Gate) Hold ¶
Hold has the gate keep its pace across runs, for this user on this machine. Its record at path holds when the last request began, and any time arXiv asked it to wait until; it is written after each request, so a run that is stopped keeps the pace it had.
A lock on a file beside the record stops a second run from asking while this one is. The system lets the lock go when the run ends, however it ends; Release writes the record and lets it go too.
It refuses while another run holds the lock, and a record it cannot read.
type ID ¶
type ID struct {
// contains filtered or unexported fields
}
ID is a paper's name on arXiv, with the version asked for or found, or none. A new-style name is four digits of year and month, a dot and four or five digits: 1809.03507. An old-style one is an archive, perhaps a subject, a slash and seven digits: astro-ph/0602086.
func ParseID ¶
ParseID reads an id as people and papers write one. That is the name alone, after arXiv:, or in an abs or pdf address on arxiv.org, with a version or without. It refuses anything else before arXiv is asked, says what it was given, and gives nil beside the error.
An old-style name with a subject is read as arXiv names the paper, without it: math.GT/0309136 is math/0309136, the only name arXiv's API answers to.
type Papers ¶
type Papers struct {
// contains filtered or unexported fields
}
Papers finds papers on arXiv, so many ids a query. Each query goes through the gate.
func New ¶
New is papers found through a searcher and a gate, most ids a query. It refuses a missing searcher or gate, and fewer than one id a query.
func (*Papers) Look ¶
Look is the papers the ids name, as products to fetch, and the ids arXiv has no paper for. Each paper is named for the version arXiv has: its latest, unless the id names one.
A version named twice, as 1809.03507 and 1809.03507v2 may, is found once. When a query fails, what was found before it comes back beside the error.
type Searcher ¶
type Searcher interface {
RawSearch(ctx context.Context,
params library.SearchParams) (*http.Response, error)
}
Searcher is what papers are looked up through. It gives the API's answer raw, as the library's Client.RawSearch does.
func NewSearcher ¶
NewSearcher is the library's client asking the API at an address, waiting so long for an answer. Its own pacing is off, since a Gate paces every request to arXiv, and so are its retries: a server that asks us to wait is waited on, not asked again.