Skip to content
Snippets Groups Projects
Unverified Commit 13c55aa0 authored by Anton Tetov Johansson's avatar Anton Tetov Johansson
Browse files

Restore old req token until rest of token stuff is fixed

parent 677a741f
No related branches found
No related tags found
No related merge requests found
"""Request a token to store in creds.json."""
#!/usr/bin/env python3
# request a token (for creds.py)
import argparse
import json
from urllib import request
from farmbot_yolo import CREDS_PATH
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--email', type=str, help="user email for token request")
parser.add_argument('--password', type=str, help="user password for token request")
opts = parser.parse_args()
print("opts %s" % opts)
def request_token(email: str, password: str):
auth_info = {'user': {'email': email, 'password': password}}
auth_info = {'user': {'email': opts.email, 'password': opts.password }}
req = request.Request('https://my.farmbot.io/api/tokens')
req.add_header('Content-Type', 'application/json')
......@@ -18,20 +22,7 @@ def request_token(email: str, password: str):
print("mqtt host [%s]" % token_info['token']['unencoded']['mqtt'])
creds_dict = {"device_id": token_info["token"]["unencoded"]["bot"],
"token": token_info['token']['encoded']}
print("rewriting creds.json")
with CREDS_PATH.open(mode="w") as fp:
json.dump(creds_dict, fp)
if __name__ == "__main__":
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--email', type=str, help="user email for token request")
parser.add_argument('--password', type=str, help="user password for token request")
opts = parser.parse_args()
print("opts %s" % opts)
request_token(opts.email, opts.password)
print("rewriting creds.py")
with open("creds.py", "w") as f:
f.write("device_id=\"%s\"\n" % token_info['token']['unencoded']['bot'])
f.write("token=\"%s\"\n" % token_info['token']['encoded'])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment