Closed ericleasemorgan closed 5 years ago
The simplest way to set the cache location is via the GUTENBERG_DATA
environment variable:
export GUTENBERG_DATA=/usr/local/gutenberg
python your_script.py
Alternatively, to set the location in code, does the snippet in the docs work for you?
# first, set up gutenberg to use a custom database location
from gutenberg.acquire import set_metadata_cache
from gutenberg.acquire.metadata import SleepycatMetadataCache
cache = SleepycatMetadataCache('/path/to/metadata.db')
cache.populate()
set_metadata_cache(cache)
# now you can use the library as normal
from gutenberg.query import get_metadata
print(get_metadata('title', 2701))
Let me know if this helps!
Setting the environment variable works quite well. Thank you for the prompt reply.
How can I use the gutenberg module get and set the location of the cache?
From what I can tell, the location of the cache defaults to my home directory through the use of local_path() and defining _DB_PATH. Is there a way to programmatically change the location of the cache to something like /usr/local/gutenberg? Something like this does not work because it returns "'str' object has no attribute 'populate'":"