[SUCS Devel] [Git][sucs/accountmanager][master] Inital dump of the sucs account manger

Imran Hussain imranh at sucs.org
Sat Mar 9 11:35:52 GMT 2019


Imran Hussain pushed to branch master at sucs / accountmanager


Commits:
16b2bfd8 by Imran Hussain at 2019-03-09T11:34:53Z
Inital dump of the sucs account manger

Can generate some useful stats and list everybody so far

- - - - -


1 changed file:

- + sucsam.py


Changes:

=====================================
sucsam.py
=====================================
@@ -0,0 +1,111 @@
+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



View it on GitLab: https://projects.sucs.org/sucs/accountmanager/commit/16b2bfd832a99ba70630429b5d3d8334d294679e

-- 
View it on GitLab: https://projects.sucs.org/sucs/accountmanager/commit/16b2bfd832a99ba70630429b5d3d8334d294679e
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/devel/attachments/20190309/0e0347fa/attachment-0001.html>


More information about the Devel mailing list