Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
Ensure GUTENBERG_MIRROR env value gets respected
Browse files Browse the repository at this point in the history
Currently the GUTENBERG_MIRROR environment variable was only getting
respected for CLI usage, not library usage. This change makes the
handling of the environment variable consistent such that the default
mirror can also be set via an environment variable when the project is
used as a library.
  • Loading branch information
c-w committed Jun 26, 2018
1 parent 284c4d3 commit 3e255eb
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions gutenberg/acquire/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from gutenberg._util.os import remove

_TEXT_CACHE = local_path('text')
_GUTENBERG_MIRROR = 'http://aleph.gutenberg.org'
_GUTENBERG_MIRROR = os.environ.get('GUTENBERG_MIRROR',
'http://aleph.gutenberg.org')


def _etextno_to_uri_subdirectory(etextno):
Expand Down Expand Up @@ -135,15 +136,13 @@ def _main():
parser = ArgumentParser(description='Download a Project Gutenberg text')
parser.add_argument('etextno', type=int)
parser.add_argument('outfile', type=FileType('w'))
parser.add_argument('--mirror', '-m', type=str)
parser.add_argument('--mirror', '-m', type=str, default=None)
parser.add_argument('--prefer-ascii', '-a', type=bool, default=False)
args = parser.parse_args()

mirror = args.mirror or os.environ.get('GUTENBERG_MIRROR')

try:
text = load_etext(args.etextno,
mirror=mirror,
mirror=args.mirror,
prefer_ascii=args.prefer_ascii)
with reopen_encoded(args.outfile, 'w', 'utf8') as outfile:
outfile.write(text)
Expand Down

0 comments on commit 3e255eb

Please sign in to comment.