From fe39635fa5172fdf364b9ace2a8dd9bd0d69161c Mon Sep 17 00:00:00 2001 From: rootzoll Date: Tue, 26 May 2020 17:43:59 +0200 Subject: [PATCH] detect no subscriptions --- .../config.scripts/blitz.subscriptions.py | 95 ++++++++++--------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/home.admin/config.scripts/blitz.subscriptions.py b/home.admin/config.scripts/blitz.subscriptions.py index 811718fda..0d014b252 100644 --- a/home.admin/config.scripts/blitz.subscriptions.py +++ b/home.admin/config.scripts/blitz.subscriptions.py @@ -47,47 +47,45 @@ You have no active or inactive subscriptions at the moment. ''',title="Info") return - while True: - - # load subscriptions and make dialog choices out of it - choices = [] - lookup = {} - lookupIndex=0 - subs = toml.load(SUBSCRIPTIONS_FILE) + # load subscriptions and make dialog choices out of it + choices = [] + lookup = {} + lookupIndex=0 + subs = toml.load(SUBSCRIPTIONS_FILE) - # list ip2tor subscriptions - for sub in subs['subscriptions_ip2tor']: - # remember subscription under lookupindex - lookupIndex += 1 - lookup[str(lookupIndex)]=sub - # add to dialog choices - if sub['active']: - activeState="on" - else: - activeState="off" - name="IP2TOR brigde for {0}".format(sub['blitz_service']) - choices.append( ("{0}".format(lookupIndex), "{0} ({1})".format(name.ljust(20), activeState)) ) + # list ip2tor subscriptions + for sub in subs['subscriptions_ip2tor']: + # remember subscription under lookupindex + lookupIndex += 1 + lookup[str(lookupIndex)]=sub + # add to dialog choices + if sub['active']: + activeState="on" + else: + activeState="off" + name="IP2TOR brigde for {0}".format(sub['blitz_service']) + choices.append( ("{0}".format(lookupIndex), "{0} ({1})".format(name.ljust(20), activeState)) ) - # show menu with options - d = Dialog(dialog="dialog",autowidgetsize=True) - d.set_background_title("RaspiBlitz Subscriptions") - code, tag = d.menu( - "You have the following subscriptions (active & inactive). Select for details:", - choices=choices, title="My Subscriptions") + # show menu with options + d = Dialog(dialog="dialog",autowidgetsize=True) + d.set_background_title("RaspiBlitz Subscriptions") + code, tag = d.menu( + "You have the following subscriptions (active & inactive). Select for details:", + choices=choices, title="My Subscriptions") - # if user cancels - if code != d.OK: return + # if user chosses CANCEL + if code != d.OK: return - # get data of selected subscrption - selectedSub = lookup[str(tag)] + # get data of selected subscrption + selectedSub = lookup[str(tag)] - # show details of selected - d = Dialog(dialog="dialog",autowidgetsize=True) - d.set_background_title("My Subscriptions") - if selectedSub['type'] == "ip2tor-v1": - if len(selectedSub['warning']) > 0: - selectedSub['warning'] = "\n{0}".formart(selectedSub['warning']) - text=''' + # show details of selected + d = Dialog(dialog="dialog",autowidgetsize=True) + d.set_background_title("My Subscriptions") + if selectedSub['type'] == "ip2tor-v1": + if len(selectedSub['warning']) > 0: + selectedSub['warning'] = "\n{0}".formart(selectedSub['warning']) + text=''' This is a IP2TOR subscription bought on {initdate} at {shop} @@ -113,19 +111,22 @@ The following additional information is available: warning=selectedSub['warning'], description=selectedSub['description'], service=selectedSub['blitz_service'] - ) + ) - if selectedSub['active']: - extraLable = "CANCEL" - else: - extraLable = "DELETE" - code = d.msgbox(text, title="Subscription Detail", ok_label="Back", extra_button=True, extra_label=extraLable ,width=70, height=30) + if selectedSub['active']: + extraLable = "CANCEL" + else: + extraLable = "DELETE" + code = d.msgbox(text, title="Subscription Detail", ok_label="Back", extra_button=True, extra_label=extraLable ,width=70, height=30) - # user wants to delete this subscription - if code == "extra": - if selectedSub['type'] == "ip2tor-v1": - # TODO: make call to blitz.ip2tor to cancel/delete subscription - pass + # user wants to delete this subscription + if code == "extra": + if selectedSub['type'] == "ip2tor-v1": + # TODO: make call to blitz.ip2tor to cancel/delete subscription + pass + + # loop until no more subscriptions or user chooses CANCEL on subscription list + mySubscriptions() ####### SSH MENU #########