|
5 | 5 | # Usage example:
|
6 | 6 | #
|
7 | 7 | # export PYTHONPATH=/your/path/to/gro
|
8 |
| -# python sugar.py --user_email ... |
9 |
| -# |
10 |
| -# If you don't want to enter the password each time, print a token, |
11 |
| -# save it and use as follows: |
| 8 | +# python sugar.py --token ... |
12 | 9 | #
|
13 |
| -# export GROAPI_TOKEN=`python sugar.py --user_email ... --print_token` |
| 10 | +# You can either save the gro api token in environment variable GROAPI_TOKEN and run |
14 | 11 | # python sugar.py
|
| 12 | +# OR use the token directly via command line argument: |
| 13 | +# python sugar.py --token YOUR_API_TOKEN_HERE |
15 | 14 | #
|
16 |
| -# Or if you don't save the token, you can pass it via cmd line |
17 |
| -# |
18 |
| -# python sugar.py --token ... |
19 | 15 | #
|
20 | 16 | # Ref: https://app.gro-intelligence.com/#/displays/23713
|
21 | 17 |
|
22 | 18 | import argparse
|
23 |
| -import getpass |
24 |
| -import sys |
25 | 19 | import unicodecsv
|
26 |
| -import groclient.lib |
27 | 20 | import os
|
28 | 21 | from api.client.crop_model import CropModel
|
29 | 22 |
|
|
32 | 25 |
|
33 | 26 | def main():
|
34 | 27 | parser = argparse.ArgumentParser(description="Gro api client")
|
35 |
| - parser.add_argument("--user_email") |
36 |
| - parser.add_argument("--user_password") |
37 |
| - parser.add_argument("--print_token", action="store_true") |
38 | 28 | parser.add_argument("--token", default=os.environ.get("GROAPI_TOKEN", None))
|
39 | 29 | args = parser.parse_args()
|
40 |
| - assert args.user_email or args.token, "Need --token or --user_email" |
41 |
| - access_token = None |
42 |
| - if args.token: |
43 |
| - access_token = args.token |
44 |
| - else: |
45 |
| - if not args.user_password: |
46 |
| - args.user_password = getpass.getpass() |
47 |
| - access_token = groclient.lib.get_access_token( |
48 |
| - API_HOST, args.user_email, args.user_password |
49 |
| - ) |
50 |
| - if args.print_token: |
51 |
| - print(access_token) |
52 |
| - sys.exit(0) |
| 30 | + assert args.token, "Need --token or the token set in GROAPI_TOKEN environment variable" |
53 | 31 |
|
54 |
| - model = CropModel(API_HOST, access_token) |
| 32 | + model = CropModel(API_HOST, args.token) |
55 | 33 | model.add_data_series(
|
56 | 34 | item="sugarcane", metric="production quantity", region="Brazil"
|
57 | 35 | )
|
|
0 commit comments