Created
November 14, 2017 17:53
-
-
Save rajadain/57d80a1fc5e1c03f87802967dcd57588 to your computer and use it in GitHub Desktop.
MapShed CLI Test Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import time | |
import requests | |
class bcolors: | |
HEADER = '\033[95m' | |
OKBLUE = '\033[94m' | |
OKGREEN = '\033[92m' | |
WARNING = '\033[93m' | |
FAIL = '\033[91m' | |
ENDC = '\033[0m' | |
BOLD = '\033[1m' | |
UNDERLINE = '\033[4m' | |
def cprint(text, color): | |
print(color + text + bcolors.ENDC) | |
MMW_LOCAL = 'http://localhost:8000/' | |
MMW_STAGING = 'https://staging.app.wikiwatershed.org/' | |
MMW = MMW_LOCAL | |
MAPSHED_PATH = 'mmw/modeling/mapshed/' | |
MAPSHED_INPUT = '{"wkaoi":"huc8__1748"}' # Schuylkill HUC-08 | |
start = time.time() | |
data = {'mapshed_input': MAPSHED_INPUT} | |
res = requests.post(MMW + MAPSHED_PATH, data=data) | |
cprint(res.text, bcolors.OKBLUE) | |
submitted = time.time() | |
job = res.json()['job'] | |
JOB_PATH = 'mmw/modeling/jobs/{}/'.format(job) | |
status = 'started' | |
cprint('==> Submitted in {}s'.format(submitted - start), bcolors.WARNING) | |
while status == 'started': | |
time.sleep(1) | |
res = requests.get(MMW + JOB_PATH) | |
status = res.json()['status'] | |
cprint(res.text, | |
bcolors.OKGREEN if status == 'complete' else bcolors.OKBLUE) | |
finish = time.time() | |
cprint('==> Evaluated in {}s'.format(finish - submitted), bcolors.WARNING) | |
cprint('==> Total time {}s'.format(finish - start), bcolors.WARNING) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment