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

Commit

Permalink
Handle missing API keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgordon committed Jul 24, 2018
1 parent 992bc77 commit 53f990b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions build-corpus
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,18 @@ from techknacq.lx import ScrabbleLexicon, StopLexicon, SentTokenizer

PROCESSES = int(.5 * mp.cpu_count())

SD_API_KEY = open(os.path.expanduser('~/.t/sd.txt')).read().strip()
BING_API_KEY = open(os.path.expanduser('~/.t/bing.txt')).read().strip()
GOOGLE_API_KEY = open(os.path.expanduser('~/.t/google.txt')).read().strip()
def read_key(fname):
full_path = os.path.expanduser(fname)
if os.path.exists(full_path):
return open(full_path).read().strip()
print('Could not read API key from', fname, file=sys.stderr)
print('Some corpus expansion methods may fail.', file=sys.stderr)
return None


SD_API_KEY = read_key('~/.t/sd.txt')
BING_API_KEY = read_key('~/.t/bing.txt')
GOOGLE_API_KEY = read_key('~/.t/google.txt')

###

Expand Down Expand Up @@ -757,7 +766,7 @@ def main(indir, outdir, sd, wiki, web):
ensure_directory(outputdir + '/web-download')

expand = sd or wiki or web

global pool
pool = mp.Pool(PROCESSES)

Expand Down

0 comments on commit 53f990b

Please sign in to comment.