README
This fetches full text from Library of Congress OCR files for LOC items. It
returns the text, when found, and None otherwise.
Usage
It can take as input either a result item from a JSON API response or the URL of an item:
from locr import Fetcher
# From item or resource URL
Fetcher.full_text_from_url('https://www.loc.gov/resource/mss85943.001811/')
# From search result
# See https://libraryofcongress.github.io/data-exploration/requests.html
url = 'https://www.loc.gov/search/?fo=json&fa=subject:cats'
response = requests.get(url)
Fetcher(response['results'][0]).full_text()
Note that the above example is not guaranteed to work. In particular, not all objects have online text available.
Fetcher may raise the following exceptions:
ObjectNotOnline: when the object does not have any online formats.AmbiguousText: when multiple fulltext options are found.UnknownFormat: when locr is not sure how to handle the fulltext link's filetype.
If you encounter these exceptions, kindly file an issue or open a PR about the newly discovered edge case. Thanks.
Why LOCR?
The Library of Congress has put OCRed full text online for many of its items. However:
- the API does not in general return the URLs to these items
- OCRed text exists on different servers, with different URL formats; there is not one single way to construct the relevant URL for an item
While full text is easy to retrieve via the web site for a single item, perhaps you, like me, would like to fetch it programmatically.
Development
This package has a humiliating lack of tests, and I have done nothing to verify appropriate versions for dependencies. It really can use your help. PRs welcome.
Metadata
Release files for locr 0.4.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| locr-0.4.4.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| locr-0.4.4-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 10.0 kB
Release files / locr-0.4.4.tar.gz
| Download URL | locr-0.4.4.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
84ed6fc24a4ff4cf93878201b3fa962fd3b1650d396c7803507a2b9797257312
|
|
BLAKE2b-256 checksum How to use checksums |
2bcf9a3f9b29e532d2d26ef576a6165b3fbcb6dd10fbcf5a054a942d0750a752
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.9.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
|
Release files / locr-0.4.4-py2.py3-none-any.whl
| Download URL | locr-0.4.4-py2.py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
aebcf14b7f9902ecc0ce36eaeb295bb1965d29a3354d3c905c43208f82290dc7
|
|
BLAKE2b-256 checksum How to use checksums |
1b44f929b34ecbf396a189e2667d71ed31094646fcd849cf5cd5e5296d99b154
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.9.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
|