ListUsers: UAP and APP => Unapproved and Approved replaced

pull/4/head
Darksider3 5 years ago
parent 389b614de9
commit a17d0ed30f

@ -53,7 +53,8 @@ class Backup:
if __name__ == "__main__": if __name__ == "__main__":
try: try:
L = ListUsers.ListUsers(config['DEFAULT']['applications_db'], uap=args.unapproved, app=args.approved) L = ListUsers.ListUsers(config['DEFAULT']['applications_db'],
unapproved=args.unapproved, approved=args.approved)
fetch = L.getFetch() fetch = L.getFetch()
B = Backup(args.file) B = Backup(args.file)
B.BackupToFile(fetch) B.BackupToFile(fetch)

@ -4,29 +4,22 @@ from lib.sqlitedb import SQLitedb
import configparser import configparser
import lib.uis.default as default_cmd # Follows -u, -a, -f flags import lib.uis.default as default_cmd # Follows -u, -a, -f flags
default_cmd.argparser.description += " - Lists Users from the Tilde database."
default_cmd.argparser.add_argument('--list', default=False, action="store_true",
help='Output a newline seperated list of users', required=False)
args = default_cmd.argparser.parse_args()
config = configparser.ConfigParser()
config.read(args.config)
class ListUsers: class ListUsers:
db = None db = None
usersFetch = None usersFetch = None
def __init__(self, db: str, uap: bool = False, app: bool = True): def __init__(self, db: str, unapproved: bool = False, approved: bool = True):
self.db = SQLitedb(db) self.db = SQLitedb(db)
if uap: # only unapproved users if unapproved: # only unapproved users
query = "SELECT * FROM `applications` WHERE `status` = '0'" query = "SELECT * FROM `applications` WHERE `status` = '0'"
elif app: # Approved users elif approved: # Approved users
query = "SELECT * FROM `applications` WHERE `status` = '1'" query = "SELECT * FROM `applications` WHERE `status` = '1'"
else: # All users else: # All users
query = "SELECT * FROM `applications`" query = "SELECT * FROM `applications`"
self.usersFetch = self.db.query(query) self.usersFetch = self.db.query(query)
def outputaslist(self) -> str: def output_as_list(self) -> str:
list_str: str = "" list_str: str = ""
query = "SELECT `username` FROM `applications` WHERE `status` = '1' ORDER BY timestamp ASC" query = "SELECT `username` FROM `applications` WHERE `status` = '1' ORDER BY timestamp ASC"
self.usersFetch = self.db.query(query) self.usersFetch = self.db.query(query)
@ -69,11 +62,18 @@ print(t.draw())
)) ))
""" """
if __name__ == "__main__": if __name__ == "__main__":
default_cmd.argparser.description += " - Lists Users from the Tilde database."
default_cmd.argparser.add_argument('--list', default=False, action="store_true",
help='Output a newline seperated list of users', required=False)
args = default_cmd.argparser.parse_args()
config = configparser.ConfigParser()
config.read(args.config)
try: try:
ret = "" ret = ""
L = ListUsers(config['DEFAULT']['applications_db'], uap=args.unapproved, app=args.approved) L = ListUsers(config['DEFAULT']['applications_db'], unapproved=args.unapproved, approved=args.approved)
if args.list: if args.list:
ret = L.outputaslist() ret = L.output_as_list()
else: else:
fetch = L.getFetch() fetch = L.getFetch()
ret += "ID %-1s| Username %-5s| Mail %-20s| Name %-17s| Registered %-8s | State |\n" % ( ret += "ID %-1s| Username %-5s| Mail %-20s| Name %-17s| Registered %-8s | State |\n" % (

Loading…
Cancel
Save