diff --git a/README.md b/README.md index 2d86f70ed93..af452afb27a 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Navigate to [api/client/samples/](api/client/samples/) and try executing the pro 4. You can also use the included `gro_client` tool as a quick way to request a single data series right on the command line. Try the following: ```sh - gro_client --metric="Production Quantity mass" --item="Corn" --region="United States" --user_email="email@example.com" + gro_client --metric="Production Quantity mass" --item="Corn" --region="United States" --token YOUR_GRO_API_TOKEN ``` The `gro_client` command line interface does a keyword search for the inputs and finds a random matching data series. It displays the data series it picked and the data points to the console. This tool is useful for simple queries, but anything more complex should be done using the provided Python packages. diff --git a/docs/quick-start-projects/gro_client-tool.rst b/docs/quick-start-projects/gro_client-tool.rst index 455bec8dc69..c928230711c 100644 --- a/docs/quick-start-projects/gro_client-tool.rst +++ b/docs/quick-start-projects/gro_client-tool.rst @@ -5,7 +5,7 @@ gro_client tool You can also use the included gro_client tool as a quick way to request a single data series right on the command line. Try the following: :: - gro_client --metric="Production Quantity mass" --item="Corn" --region="United States" --user_email="email@example.com" + gro_client --metric="Production Quantity mass" --item="Corn" --region="United States" --token YOUR_GRO_API_TOKEN The gro_client command line interface does a keyword search for the inputs and finds a random matching data series. It displays the data series it picked in the command line and writes the data points out to a file in the current directory called gro_client_output.csv. This tool is useful for simple queries, but anything more complex should be done using the Python packages. \ No newline at end of file diff --git a/groclient/cli.py b/groclient/cli.py index b2747c3e23b..09a259959b3 100644 --- a/groclient/cli.py +++ b/groclient/cli.py @@ -66,23 +66,14 @@ def main(): # pragma: no cover Usage examples: gro_client --item=soybeans --region=brazil --partner_region china --metric export gro_client --item=sesame --region=ethiopia - gro_client --user_email=john.doe@example.com --print_token For more information use --help """ parser = argparse.ArgumentParser(description="Gro API command line interface") - parser.add_argument("--user_email") - parser.add_argument("--user_password") parser.add_argument("--item") parser.add_argument("--metric") parser.add_argument("--region") parser.add_argument("--partner_region") parser.add_argument("--file") - parser.add_argument( - "--print_token", - action="store_true", - help="Output API access token for the given user email and password. " - "Save it in GROAPI_TOKEN environment variable.", - ) parser.add_argument( "--token", default=os.environ.get("GROAPI_TOKEN"), @@ -95,25 +86,9 @@ def main(): # pragma: no cover print(groclient.lib.get_version_info().get("api-client-version")) return - assert ( - args.user_email or args.token - ), "Need --token, or --user_email, or $GROAPI_TOKEN" - access_token = None - - if args.token: - access_token = args.token - else: - if not args.user_password: - args.user_password = getpass.getpass() - access_token = groclient.lib.get_access_token( - groclient.cfg.API_HOST, args.user_email, args.user_password - ) - - if args.print_token: - print(access_token) - return + assert args.token, "Need --token, or the access token to be set in environment variable: $GROAPI_TOKEN" - client = GroClient(groclient.cfg.API_HOST, access_token) + client = GroClient(groclient.cfg.API_HOST, args.token) if ( not args.metric diff --git a/groclient/lib.py b/groclient/lib.py index 82dc95093eb..6a3f20acbc3 100644 --- a/groclient/lib.py +++ b/groclient/lib.py @@ -90,50 +90,6 @@ def get_default_logger(): return logger -def get_access_token(api_host, user_email, user_password, logger=None): - """Request an access token. - This is a DEPRECATED function and will no longer be supported after November 1, 2023! - - Parameters - ---------- - api_host : string - The API host's url, excluding 'https://' - ex. 'api.gro-intelligence.com' - user_email : string - Email address associated with user's Gro account - user_password : string - Password for user's Gro account - logger : logging.Logger - Alternative logger object if wanting to use a non-default one. - Otherwise get_default_logger() will be used. - - Returns - ------- - accessToken : string - - """ - warnings.warn( - f"get_access_token() is deprecated and will be removed on November 1, 2023.", - DeprecationWarning, - 2, - ) - retry_count = 0 - if not logger: - logger = get_default_logger() - while retry_count <= cfg.MAX_RETRIES: - get_api_token = requests.post( - "https://" + api_host + "/api-token", - data={"email": user_email, "password": user_password}, - ) - if get_api_token.status_code == 200: - logger.debug("Authentication succeeded in get_access_token") - return get_api_token.json()["data"]["accessToken"] - - logger.warning(f"Error in get_access_token: {get_api_token}") - retry_count += 1 - raise Exception(f"Giving up on get_access_token after {retry_count} tries.") - - def redirect(old_params, migration): """Update query parameters to follow a redirection response from the API.