Interactive interface for browsing global, full-resolution satellite imagery
process colormaps and request GC concurrently
Jason Kent73a37b1aee78
diff --git a/tasks/python3/getCapabilities.py b/tasks/python3/getCapabilities.pyindex 6b9b958f4..34351bfe8 100755--- a/tasks/python3/getCapabilities.py+++ b/tasks/python3/getCapabilities.py@@ -1,5 +1,7 @@#!/usr/bin/env python+from concurrent.futures import as_completed, wait, ThreadPoolExecutor+from requests_futures.sessions import FuturesSessionfrom optparse import OptionParserfrom datetime import datetimefrom collections import OrderedDict@@ -117,22 +119,24 @@ def process_remote(entry):# Fetch every colormap from the API and write response to file systemdef process_colormaps():- print("%s: Fetching %d colormaps" % (prog, len(colormaps)))+ print("%s: Fetching %d colormaps..." % (prog, len(colormaps)))sys.stdout.flush()if not os.path.exists(colormaps_dir):os.makedirs(colormaps_dir)- for link in list(colormaps.values()):- try:- response = http.request("GET", link)- contents = response.data- output_file = os.path.join(colormaps_dir, os.path.basename(link))- with open(output_file, "w") as fp:- fp.write(contents.decode('utf-8'))- except Exception as e:- sys.stderr.write("%s: WARN: Unable to fetch %s: %s\n" %- (prog, link, str(e)))- global warning_count- warning_count += 1+ with FuturesSession(max_workers=100) as fs:+ futures = { fs.get(link):link for link in colormaps.values() }+ for future in as_completed(futures):+ fileName = futures[future]+ try:+ data = future.result()+ output_file = os.path.join(colormaps_dir, os.path.basename(fileName))+ with open(output_file, "w") as fp:+ fp.write(data.text)+ except Exception as e:+ sys.stderr.write("%s: WARN: Unable to fetch %s: %s\n" %+ (prog, link, str(e)))+ global warning_count+ warning_count += 1# Fetch every vectorstyle from the API and write response to file systemdef process_vectorstyles():@@ -176,10 +180,12 @@ def process_vectordata():tolerant = config.get("tolerant", False)if "wv-options-fetch" in config:+ executor = ThreadPoolExecutor(3)+ gc_futures = []for entry in config["wv-options-fetch"]:try:remote_count += 1- process_remote(entry)+ gc_futures.append(executor.submit(process_remote, entry))except Exception as e:if tolerant:warning_count += 1@@ -187,6 +193,7 @@ if "wv-options-fetch" in config:else:error_count += 1sys.stderr.write("%s: ERROR: %s\n" % (prog, str(e)))+ wait(gc_futures)if colormaps:process_colormaps()if vectorstyles: