From 6e86bf11bbb6dc29a2b5edac6e1c3b9b4905ccb0 Mon Sep 17 00:00:00 2001 From: Darksider3 Date: Sat, 12 Oct 2019 19:21:33 +0200 Subject: [PATCH] -a Flag: default false, do action on only approved users --- private/ListUsers.py | 12 +++++++----- private/lib/CFG.py | 4 +++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/private/ListUsers.py b/private/ListUsers.py index 8314d0f..0e190db 100644 --- a/private/ListUsers.py +++ b/private/ListUsers.py @@ -8,12 +8,14 @@ class ListUsers: db = None usersFetch = None - def __init__(self, ap: bool): + def __init__(self, uap: bool = CFG.args.unapproved, a: bool = CFG.args.approved): self.db = SQLitedb(CFG.REG_FILE) - if not ap: - query = "SELECT * FROM `applications` WHERE status = '1'" - else: + if uap: # only unapproved users query = "SELECT * FROM `applications` WHERE status = '0'" + elif a: # Approved users + query = "SELECT * FROM `applications` WHERE status = '1'" + else: # All users + query = "SELECT * FROM `applications`" self.usersFetch = self.db.query(query) def prettyPrint(self): @@ -25,7 +27,7 @@ class ListUsers: if __name__ == "__main__": try: - L = ListUsers(CFG.args.unapproved) + L = ListUsers() fetch = L.getFetch() # MAYBE best solution: https://pypi.org/project/texttable/ # examle: diff --git a/private/lib/CFG.py b/private/lib/CFG.py index 861b052..d8efe95 100644 --- a/private/lib/CFG.py +++ b/private/lib/CFG.py @@ -12,7 +12,9 @@ argparser.add_argument('-c', '--config', default=cwd, type=str, help='Path to configuration file', required=False) # store_true just stores true when the command is supplied, so it doesn't need choices nor types argparser.add_argument('-u', '--unapproved', default=False, action="store_true", - help='List only unapproved users', required=False) + help='only unapproved users. Default is only approved.', required=False) +argparser.add_argument('-a', '--approved', default=False, action="store_true", + help="Only approved Users.", required=False) args = argparser.parse_args() CONF_FILE = args.config