From a1765500ed1101b864352d2c8df8b24af7206155 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Tue, 8 Nov 2022 17:09:54 +0300 Subject: [PATCH] Add make loginning on instances (manually) --- funkwhale_cli.py | 26 ++++++++++++++++++++++++-- src/fw_api.py | 2 ++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/funkwhale_cli.py b/funkwhale_cli.py index 2e7b380..cdd1e45 100644 --- a/funkwhale_cli.py +++ b/funkwhale_cli.py @@ -1,4 +1,4 @@ -from src.fw_api import select_instance +from src.fw_api import s, select_instance, instance from src.fw_radios import list_radios import json, sys from loguru import logger @@ -11,7 +11,9 @@ def main(): logger.add(sys.stderr, filter='src.fw_api') logger.add(sys.stderr, filter='src.fw_radios') while True: - menu = ('Radios', 'Switch instance' ) + menu =['Radios', 'Switch instance'] + if not s.headers.get('Authorization'): + menu.append('Sign in') ids = fzf.prompt(menu) selected = ids[0] @@ -23,6 +25,26 @@ def main(): list_instances = conf.get('public_list_instances') instance = fzf.prompt(list_instances, '--header \'Select instance\'')[0] select_instance(instance) + if selected == 'Sign in': + print(f''' +If You want sign in, please visit: +https://{instance}/settings/applications/new +And fill Name funkwhale-cli +Scopes: mark Read + +Insert token from "Access token" here''') + register_token = input() + with open('.auth.json', 'rt') as f: + tkns = json.loads(f.read()) + with open('.auth.json', 'wt') as f: + tkns[instance] = register_token + f.write(json.dumps(tkns)) + del tkns + del register_token + del f + + select_instance(instance) + if __name__ == '__main__': diff --git a/src/fw_api.py b/src/fw_api.py index ad6a3bf..d06122d 100644 --- a/src/fw_api.py +++ b/src/fw_api.py @@ -22,6 +22,8 @@ else: def select_instance(new_instance=None): global instance instance = new_instance + with open('.auth.json', 'rt') as f: + auth = json.loads(f.read()) new_token = auth.get(instance) s.headers.update({"Authorization": None}) player.http_header_fields = []