Loading sucsam.py 0 → 100644 +111 −0 Original line number Diff line number Diff line import os import sys import readline import psycopg2 def mainMenu(): print("\nPlease choose an option") print("[h] Diplay some help") print("[qs] View quick stats of all accounts") print("[la] View a list of ALL accounts") print("[q] Quit") option = input("Option: ") print("\n") if (option == "h"): print("help text comming soon") mainMenu() elif (option == "q"): DBconn.close() sys.exit(0) elif (option == "qs"): quickStats() mainMenu() elif (option == "la"): listUsers() mainMenu() else: mainMenu() def quickStats(): print("There are:") print(str(len(students))+" Students") paidyears = {} for item in students: paidyears[item[1]] = paidyears.get(item[1], 0) + 1 for item in sorted(paidyears): print(" - " + str(paidyears[item]) + ": " + str(item)) print(str(len(societies))+" Societies") paidyears = {} for item in societies: paidyears[item[1]] = paidyears.get(item[1], 0) + 1 for item in sorted(paidyears): print(" - " + str(paidyears[item]) + ": " + str(item)) print(str(len(associates))+" Associates") paidyears = {} for item in associates: paidyears[item[1]] = paidyears.get(item[1], 0) + 1 for item in sorted(paidyears): print(" - " + str(paidyears[item]) + ": " + str(item)) print(str(len(lifers))+" Lifers") print(str(len(hons))+" Honoary") def listUsers(): print("Students: ") for student in students: print(str(student[0]) + " (" + str(student[1]) + ")") print("\nSocieties: ") for soc in societies: print(str(soc[0]) + " (" + str(soc[1]) + ")") print("\nAssociates: ") for associate in associates: print(str(associate[0]) + " (" + str(associate[1]) + ")") print("\nLifers: ") for life in lifers: print(str(life[0]) + " (" + str(life[1]) + ")") print("\nHonoary: ") for hon in hons: print(str(hon[0]) + " (" + str(hon[1]) + ")") ### MAIN ### if (os.geteuid() == 0): print("Don't run this as root!") sys.exit(1) #This tool was written for python *3* #but doesn't mean we can't support 2 as well :) try: input = raw_input except NameError: pass #try and connect to the db try: DBconn = psycopg2.connect(database="sucs") except: print("Can't connect to the SUCS DB, suicidng!") sys.exit(2) #store some data from to db to operate on cur = DBconn.cursor() cur.execute("SELECT username,paid from members WHERE type=1 ORDER BY paid") students = cur.fetchall() cur.execute("SELECT username,paid from members WHERE type=2 ORDER BY paid") societies = cur.fetchall() cur.execute("SELECT username,paid from members WHERE type=5 ORDER BY paid") associates = cur.fetchall() cur.execute("SELECT username,paid from members WHERE type=4 ORDER BY username") lifers = cur.fetchall() cur.execute("SELECT username,paid from members WHERE type=3 ORDER BY username") hons = cur.fetchall() cur.close() print("Welcome to the SUCS Account Manager!") mainMenu() No newline at end of file Loading
sucsam.py 0 → 100644 +111 −0 Original line number Diff line number Diff line import os import sys import readline import psycopg2 def mainMenu(): print("\nPlease choose an option") print("[h] Diplay some help") print("[qs] View quick stats of all accounts") print("[la] View a list of ALL accounts") print("[q] Quit") option = input("Option: ") print("\n") if (option == "h"): print("help text comming soon") mainMenu() elif (option == "q"): DBconn.close() sys.exit(0) elif (option == "qs"): quickStats() mainMenu() elif (option == "la"): listUsers() mainMenu() else: mainMenu() def quickStats(): print("There are:") print(str(len(students))+" Students") paidyears = {} for item in students: paidyears[item[1]] = paidyears.get(item[1], 0) + 1 for item in sorted(paidyears): print(" - " + str(paidyears[item]) + ": " + str(item)) print(str(len(societies))+" Societies") paidyears = {} for item in societies: paidyears[item[1]] = paidyears.get(item[1], 0) + 1 for item in sorted(paidyears): print(" - " + str(paidyears[item]) + ": " + str(item)) print(str(len(associates))+" Associates") paidyears = {} for item in associates: paidyears[item[1]] = paidyears.get(item[1], 0) + 1 for item in sorted(paidyears): print(" - " + str(paidyears[item]) + ": " + str(item)) print(str(len(lifers))+" Lifers") print(str(len(hons))+" Honoary") def listUsers(): print("Students: ") for student in students: print(str(student[0]) + " (" + str(student[1]) + ")") print("\nSocieties: ") for soc in societies: print(str(soc[0]) + " (" + str(soc[1]) + ")") print("\nAssociates: ") for associate in associates: print(str(associate[0]) + " (" + str(associate[1]) + ")") print("\nLifers: ") for life in lifers: print(str(life[0]) + " (" + str(life[1]) + ")") print("\nHonoary: ") for hon in hons: print(str(hon[0]) + " (" + str(hon[1]) + ")") ### MAIN ### if (os.geteuid() == 0): print("Don't run this as root!") sys.exit(1) #This tool was written for python *3* #but doesn't mean we can't support 2 as well :) try: input = raw_input except NameError: pass #try and connect to the db try: DBconn = psycopg2.connect(database="sucs") except: print("Can't connect to the SUCS DB, suicidng!") sys.exit(2) #store some data from to db to operate on cur = DBconn.cursor() cur.execute("SELECT username,paid from members WHERE type=1 ORDER BY paid") students = cur.fetchall() cur.execute("SELECT username,paid from members WHERE type=2 ORDER BY paid") societies = cur.fetchall() cur.execute("SELECT username,paid from members WHERE type=5 ORDER BY paid") associates = cur.fetchall() cur.execute("SELECT username,paid from members WHERE type=4 ORDER BY username") lifers = cur.fetchall() cur.execute("SELECT username,paid from members WHERE type=3 ORDER BY username") hons = cur.fetchall() cur.close() print("Welcome to the SUCS Account Manager!") mainMenu() No newline at end of file