def main(): # Decorative purpose. init() # Nope, this is not the real otog.cf password XD. mydb = mysql.connector.connect( host="localhost", user="******", passwd="00000000", # Original for otog.cf was : # passwd='0000', database="OTOG", ) myCursor = mydb.cursor(buffered=True) # for keybord interupt. print(ogogi + "Grader started. Waiting for submission...") kb = KBHit() while True: # Looking for keyboard interupt. if kb.kbhit(): if kb.getch() == ":": # Do functions. print(ogogi + "Keyboard interupted. Entering command mode.") kb.set_normal_term() # Command mode while True: cmd, args = cmdMode.run() # Shutdown signal if cmd == abb.INCMD["SHUTDOWN"]: # Good-bye message print(ogogi + "Bye") exit(0) elif cmd == abb.INCMD["RELOAD"]: # Reload modules in args for e in args: if e == "grader": print( abb.error + "'grader' itself cannot be reloaded. Please restart the program manually." ) try: importlib.reload(importlib.import_module(e)) except: print(abb.error + "'" + e + "' cannot be reloaded.") elif cmd == abb.INCMD["EXIT"]: break kb.set_kbhit_term() print(ogogi + "Command mode exited. Continue waiting for submission.") myCursor.execute("SELECT * FROM Result WHERE status = 0 ORDER BY time") submission = myCursor.fetchone() if submission != None: print(abb.bold + Fore.GREEN + "\t--> recieved.\n" + Style.RESET_ALL) print( str(datetime.datetime.now().strftime("[ %d/%m/%y %H:%M:%S ]")) + " -----------------------------" ) myCursor.execute( "SELECT * FROM Problem WHERE id_Prob = " + str(submission[3]) ) probInfo = myCursor.fetchone() # Submit result sql = "UPDATE Result SET result = %s, score = %s, timeuse = %s, status = 1, errmsg = %s WHERE idResult = %s" val = onRecieved(submission, probInfo, mydb) myCursor.execute(sql, val) print("---------------------------------------------------") print("\n" + ogogi + "Finished grading session. Waiting for the next one.") mydb.commit() time.sleep(config.gradingInterval)