def contestCommand(data): session = requests.Session() command = data.get('contest_command') if command == 'get': contestData = readContest(data.get('contest'), session) if not contestData.get('inProgress'): timeTo = contestData.get('timeTo') if timeTo and timeTo.total_seconds() > 0: print('Contest is not in progress.') print(f'Contest begins in {timeTo}.') return else: print('The contest seems to be over.') if len(contestData.get('problems')) > 0: print( 'Do you want to get the problems from the contest anyways?' ) if not yes(): return solved = getCommand({ **data, 'command': 'get', 'problem': contestData.get('problems'), }) if solved: if not data.get('submit'): print("Some problems were unarchived from the .solved folder:") print(", ".join(solved)) print("Do you want to submit them?") if not yes(): return for problem in solved: submitCommand({"problem": problem})
def contestCommand(data): session = requests.Session() contest = data.get('contest-id') contestData = readContest(contest, session) if contestData.get('timeState') == TimeState.NotStarted: timeTo = contestData.get('timeTo') print('Contest has not started yet.') print(f'Contest begins in {timeTo}.') print("Do you want to run this command again when the contest starts?") if not yes(): return print("Waiting for contest to start...") while contestData.get('timeState') == TimeState.NotStarted: timeTo = contestData.get('timeTo') timeToInSeconds = timeTo.total_seconds() if timeTo is not None else -1 # the -1 denotes that we don't know how long it is to contest start, and will result in the code checking every second if timeToInSeconds > 10: time.sleep(timeToInSeconds - 10) else: time.sleep(1) contestData = readContest(contest, session) elif contestData.get('timeState') == TimeState.Ended: print('The contest seems to be over.') if len(contestData.get('problems')) > 0: print('Do you want to get the problems from the contest anyways?') if not yes(): return solved = getCommand({ **data, 'command': 'get', 'problem': contestData.get('problems'), 'language': None, }) #update config with new problems config = getConfig() config['contest'] = contestData['problemMap'] saveConfig() if solved: if not data.get('submit'): print("Some problems were unarchived from the .solved folder:") print(", ".join(solved)) print("Do you want to submit them?") if not yes(): return for problem in solved: submitCommand({"problem": problem, "force": True, "archive": True})
def confirm(problemName, programFile): print("Are you sure you want to submit?") print("Problem: " + problemName) print("File: " + programFile["relativePath"]) print("Language: " + guessLanguage(programFile)) return yes()
def checkCorrectDomain(problemName, commandName): if "." in problemName: hostPrefix = problemName.split(".")[0] hostname = hostPrefix + ".kattis.com" cfg = getConfig() actualHostname = cfg["kattis"]["hostname"] if hostname != actualHostname: print(f'Warning: The problem you are trying to {commandName} looks like it is part of the subdomain "{hostname}", ' f'while your instance of Kat tool currently uses "{actualHostname}". Would you like to switch ' f'beforehand?') if yes(): cfg["kattis"]["hostname"] = hostname saveConfig()
def archiveCommand(data): folder = ".archive/" if data.get('target'): folder = data.get('target') if data.get("all"): folder = data.get("all") print(f"Warning: You are about to archive all problems in your current folder to {folder}. Do you want to continue?") if not yes(): return data["problem"] = [x for x in os.listdir() if not x.startswith(".")] if data["problem"] == []: print("Warning: No problems will be removed as a result of this command") for problem in data['problem']: archive(problem, folder)
def main(): try: data = vars(parse()) command = data.get("command") if command in execCommand: execCommand[command](data) except (Exception) as error: print() print(*traceback.format_exception(None, error, error.__traceback__)) print(f"Error occurred:\n {error}\n") print( "The program ran into a problem while running, do you want to create an issue on github?" ) if yes(): submitError(error)
def main(): try: data = parse(sys.argv[1:]) command = data.get("command") if command in execCommand: execCommand[command](data) else: print( 'Welcome to the Kat CLI for Kattis. To use, write "kattis [COMMAND] with one of the following commands:' ) print(", ".join(execCommand)) except (Exception) as error: print() print(*traceback.format_exception(None, error, error.__traceback__)) print(f"Error occurred:\n {error}\n") print( "The program ran into a problem while running, do you want to create an issue on github?" ) if yes(): submitError(error)
def unarchiveCommand(data): folder = None if data.get('target'): folder = data.get('target') if data.get("all"): folder = data.get('all') if folder is None: folder = ".archive/" print( f"You are about to unarchive all problems from {folder}. Are you sure you want to continue?" ) if not yes(): return data["problem"] = [ x for x in os.listdir(folder) if not x.startswith(".") ] for problem in data['problem']: if folder is not None: if not folder.startswith("."): folder = "." + folder if not folder.endswith("/"): folder += "/" unarchive(problem, folder)
def promptToFetch(problemName): print("This problem is not present...") print("Do you want to get it?") if yes(): print("Getting problem...") fetchProblem(problemName)