From bd8d3a404164103ea7a3a2f7a5c1fea85c04d9b1 Mon Sep 17 00:00:00 2001 From: Dominik Roth Date: Fri, 29 May 2020 21:06:58 +0200 Subject: [PATCH] initial commit --- babbageCup.py | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 babbageCup.py diff --git a/babbageCup.py b/babbageCup.py new file mode 100644 index 0000000..30e13f6 --- /dev/null +++ b/babbageCup.py @@ -0,0 +1,114 @@ +import _winreg +import win32api +import win32print +import time +import datetime +import os + +blacklist = ["Fax","Microsoft Print to PDF","Microsoft XPS Document Writer"] + +def printers(): + path = r'SYSTEM\CurrentControlSet\Control\Print\Printers' + hKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, path) + + subkeyCnt, valuesCnt, modtime = _winreg.QueryInfoKey(hKey) + + for n in xrange(subkeyCnt): + subName = _winreg.EnumKey(hKey, n) + p2 = path + '\\' + subName + hK2 = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, p2) + + yield (_winreg.QueryValueEx(hK2, 'Name')[0], + _winreg.QueryValueEx(hK2, 'Port')[0]) + + _winreg.CloseKey(hK2) + + _winreg.CloseKey(hKey) + +def getInputs(): + pages = int(raw_input(" [>] How many pages do you want to print? [0 = Infinite]> ")) + file_path = raw_input(" [>] Drag and Drop the file, you want to print and press enter...") + while True: + temp = raw_input(" [>] Launch [n]ow or at specified date and [t]ime?> ") + if temp=="n": + return pages,file_path,False + elif temp=="t": + return pages,file_path,True + print(" Error: Please only enter 'n' or 't'") + +def babbage(pages,file_path): + os.system("cls") + print(""" + ,----,------------------------------,------. + | ## | [BabbageCup] | - | + | ## | | - | + | |------------------------------| - | + | ||............................|| | + | ||,- -.|| | + | ||___ ___|| ##| + | ||---`--------------------'---|| | + `----'|_|______________________==__|`------'\n""") + if pages==0: + pages = 1000000 + for page in range(pages): + for p in printers(): + if p[0] not in blacklist: + try: + print(" [*] Printing page "+str(page)+" on printer '"+str(p[0])+"'") + win32print.SetDefaultPrinter(p[0]) + win32api.ShellExecute(0, "print", "babbageCup.py", None, ".", 0) + except Exception as e: + print(" [!] Error: "+str(e[2])+"\n") + time.sleep(0.5) + +def waitInput(): + print("\n [+] Now {"+datetime.datetime.today().strftime('%H:%M %d.%m.%Y')+"}") + t = datetime.datetime(int(raw_input(" [>] Year ["+str(datetime.datetime.today().year)+"]> ")),int(raw_input(" [>] Month ["+str(datetime.datetime.today().month)+"]> ")),int(raw_input(" [>] Day ["+str(datetime.datetime.today().day)+"]> ")),int(raw_input(" [>] Hour ["+str(datetime.datetime.today().hour)+"]> ")),int(raw_input(" [>] Minute ["+str(datetime.datetime.today().minute)+"]> ")),0) + print(" [+] Launch {"+t.strftime('%H:%M %d.%m.%Y')+"}\n") + now = datetime.datetime.today() + print(" [*] Launching in T-"+str((t-now).seconds)+" seconds") + time.sleep((t-now).seconds) + +if __name__ == '__main__': + os.system("cls") + + for i in range(3): + os.system("cls") + print(""" + ,----,------------------------------,------. + | ## | [BabbageCup] | - | + | ## | | - | + | |------------------------------| - | + | ||............................|| | + | ||,- -.|| | + | ||___ ~~~~~~~~~~~~~~~~~~~~ ___|| ##| + | ||---`--------------------'---|| | + `----'|_|______________________==__|`------'\n""") + time.sleep(0.5) + os.system("cls") + print(""" + ,----,------------------------------,------. + | ## | [BabbageCup] | - | + | ## | | - | + | |------------------------------| - | + | ||............................|| | + | ||,- -.|| | + | ||___ ___|| ##| + | ||---`--------------------'---|| | + `----'|_|______________________==__|`------'\n""") + time.sleep(0.5) + + print(" [*] Printers found:") + for p in printers(): + if p[0] not in blacklist: + print(" "+str(p[0])) + print("") + + time.sleep(0.2) + + p,f,l = getInputs() + if l: + waitInput() + else: + raw_input("\n [#] Press >enter< to start") + babbage(p,f)