Skip to content

Commit

Permalink
remove get_access_token
Browse files Browse the repository at this point in the history
  • Loading branch information
prabesh-paudel committed Dec 19, 2023
1 parent c64f473 commit 6be74c8
Showing 1 changed file with 6 additions and 28 deletions.
34 changes: 6 additions & 28 deletions api/client/samples/crop_models/sugar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,18 @@
# Usage example:
#
# export PYTHONPATH=/your/path/to/gro
# python sugar.py --user_email ...
#
# If you don't want to enter the password each time, print a token,
# save it and use as follows:
# python sugar.py --token ...
#
# export GROAPI_TOKEN=`python sugar.py --user_email ... --print_token`
# You can either save the gro api token in environment variable GROAPI_TOKEN and run
# python sugar.py
# OR use the token directly via command line argument:
# python sugar.py --token YOUR_API_TOKEN_HERE
#
# Or if you don't save the token, you can pass it via cmd line
#
# python sugar.py --token ...
#
# Ref: https://app.gro-intelligence.com/#/displays/23713

import argparse
import getpass
import sys
import unicodecsv
import groclient.lib
import os
from api.client.crop_model import CropModel

Expand All @@ -32,26 +25,11 @@

def main():
parser = argparse.ArgumentParser(description="Gro api client")
parser.add_argument("--user_email")
parser.add_argument("--user_password")
parser.add_argument("--print_token", action="store_true")
parser.add_argument("--token", default=os.environ.get("GROAPI_TOKEN", None))
args = parser.parse_args()
assert args.user_email or args.token, "Need --token or --user_email"
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(
API_HOST, args.user_email, args.user_password
)
if args.print_token:
print(access_token)
sys.exit(0)
assert args.token, "Need --token or the token set in GROAPI_TOKEN environment variable"

model = CropModel(API_HOST, access_token)
model = CropModel(API_HOST, args.token)
model.add_data_series(
item="sugarcane", metric="production quantity", region="Brazil"
)
Expand Down

0 comments on commit 6be74c8

Please sign in to comment.