From 13c55aa05aabdfe2482b8bea59b41ec6e5c036ee Mon Sep 17 00:00:00 2001
From: Anton Tetov <anton@tetov.se>
Date: Mon, 13 Jun 2022 16:19:48 +0200
Subject: [PATCH] Restore old req token until rest of token stuff is fixed

---
 src/farmbot_yolo/request_token.py | 45 +++++++++++++------------------
 1 file changed, 18 insertions(+), 27 deletions(-)

diff --git a/src/farmbot_yolo/request_token.py b/src/farmbot_yolo/request_token.py
index 8c1622e..ef793f9 100644
--- a/src/farmbot_yolo/request_token.py
+++ b/src/farmbot_yolo/request_token.py
@@ -1,37 +1,28 @@
-"""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
-
-
-def request_token(email: str, password: str):
-    auth_info = {'user': {'email': email, 'password': password}}
-
-    req = request.Request('https://my.farmbot.io/api/tokens')
-    req.add_header('Content-Type', 'application/json')
-    response = request.urlopen(req, data=json.dumps(auth_info).encode('utf-8'))
-
-    token_info = json.loads(response.read().decode())
-
-    print("mqtt host [%s]" % token_info['token']['unencoded']['mqtt'])
-
-    creds_dict = {"device_id": token_info["token"]["unencoded"]["bot"],
-                  "token": token_info['token']['encoded']}
+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)
 
-    print("rewriting creds.json")
-    with CREDS_PATH.open(mode="w") as fp:
-        json.dump(creds_dict, fp)
+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')
+response = request.urlopen(req, data=json.dumps(auth_info).encode('utf-8'))
 
-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()
+token_info = json.loads(response.read().decode())
 
-    print("opts %s" % opts)
+print("mqtt host [%s]" % token_info['token']['unencoded']['mqtt'])
 
-    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'])
-- 
GitLab