def createProject(mode, projectName): path = globalPath path += '/projects/' + projectName try: os.mkdir(path) file = open(path + '/LogFile.txt', 'w+') file.write('A basic Log File. Used to log errors so they don\'t display on the main console') file.close() file = open(path + '/main.py', 'w+') file.write('''# A basic main.py template file. imports my most commonly used basic modules. import random import math import os # Your main function class goes here def main(): print('Filler Code') ''') file.close() except OSError: textTesting(mode,'Creation of Project %s failed' % projectName) else: textTesting(mode, 'Successfully created Project %s' % projectName)
def chat(mode, name): textTesting(mode, "C.L.I.F.F.: Hello {0}! What is going on?".format(name)) while True: answer = inputTesting(mode, "Connor: ".format(name)) if "bye" in answer: textTesting(mode, "C.L.I.F.F.: Goodbye {}".format(name)) break
def openNote(mode, note): try: newNote = open(note, 'r') textTesting(mode, newNote.read()) newNote.close() except FileNotFoundError: textTesting(mode, '{} doesn\'t exist'.format(note))
def deleteNote(mode, name): try: print(globalPath) os.remove('{0}/journals/notes/{1}'.format(globalPath,name)) except FileNotFoundError: textTesting(mode, '{} not found'.format(name))
def testProtocol(mode): textTesting(mode, 'Protocols working as expected sir')
def listProtocols(mode): for item in protocols: textTesting(mode, item)
def createFile(mode, file): file = open(file, 'w+') file.close() textTesting(mode, 'File Created')
def readFile(mode, file): file = open(file, 'r') textTesting(mode, file.read()) file.close()
def clearFile(mode, file): file = open(file, 'w+') file.close() textTesting(mode, 'File Cleared')
def appendNote(mode, note): try: newNote = open(note, 'a+') except FileNotFoundError: textTesting(mode, 'Note not found')
def time_convert(sec): mins = sec // 60 sec = sec % 60 hours = mins // 60 mins = mins % 60 textTesting(mode, "Time Lapsed = {0}:{1}:{2}".format(int(hours),int(mins),sec))
def openProject(mode, projectName): os.chdir('{0}/projects/{1}'.format(globalPath, projectName)) textTesting(mode, 'directory changed into project {}'.format(projectName))
def pickANumber(mode, start, end): number = random.randint(int(start), int(end)) textTesting(mode, 'picking a number between {0} and {1}'.format(start, end)) textTesting(mode, 'Your number is {0}'.format(number))
def processAnswer(mode, name, answer, lastCommand): global inProject global projectName answer = answer.lower() if answer == '' or answer == 'run last command': answer = lastCommand # Hello World example if answer == 'hello': textTesting(mode, 'hello') elif "open brain" in answer: textTesting(mode, "Opening brain") system.openBrain(mode) inProject = True projectName = "brain" elif "exit brain" in answer: textTesting(mode, "Exiting Brain") os.chdir("/home/connor/CLIFF/CLIFF") inProject = False elif "i want cheese" in answer: textTesting(mode, "You are not welcome here Brock!") t.sleep(5) os.system("shutdown now") elif "differentiation" in answer or "derivative" in answer: equation = input("C.L.I.F.F.: What is the equation?") variable = input("C.L.I.F.F.: What is the variable of differention?") print(mymath.differentiate(equation, variable)) elif "integrate" in answer: equation = input("C.L.I.F.F.: What is the equation?") variable = input("C.L.I.F.F.: What is the variable of integration?") print(mymath.integrate(equation, variable)) elif 'pick a card' in answer: pickACard.pickACard(mode) elif answer == 'chat': chatbot.chat(mode, name) # Prints options elif 'options' in answer: system.options() # Exits program elif 'exit' in answer: textTesting(mode, 'Goodbye ' + name) elif 'good night' in answer: textTesting(mode, 'Good night ' + name) textTesting(mode, 'Get some sleep') # Sends email elif 'email' in answer: productivity.gmail() # Sets reminder elif 'reminder' in answer: if mode == 'silent': productivity.reminderSilent(name) elif mode == 'production': productivity.reminderProduction(name) # prints the time elif 'time' in answer and 'timer' not in answer: if mode == 'silent': system.currentTimeSilent() elif mode == 'production': system.currentTimeProduction() # Flips a coin elif 'flip a coin' in answer: flipACoin.flipacoin(mode) elif 'stopwatch' in answer: system.stopwatch(mode) # Rolls a dice elif 'roll a dice' in answer: rollADice.rolladice(mode) # Plays quick game of rock paper scissors elif 'rock paper scissors' in answer: RockPaperScissors.rockpaperscissors(mode) # plays minesweeper elif 'minesweeper' in answer: mineSweeper.minesweeper(mode) # Plays tic tac toe elif 'tictactoe' in answer: ticTacToe.ticTacToe(mode) # Plays Hangman elif 'hangman' in answer: hangman.hangman(mode) # Initializes a command line instance: Specific to silent mode, more of a development option elif 'command line' in answer: system.command_line() # Initializes a python line instance: Specific to silent mode, more of a development option elif 'python shell' in answer: system.python_shell() # Runs my physics engine elif 'physics engine' in answer: physics.run() #picks a number elif 'pick a number' in answer: numbers = answer.replace('pick a number between', '') number1 = numbers.split(' and ')[0] number2 = numbers.split(' and ')[1] pickANumber.pickANumber(mode, number1, number2) # runs a simple ping request, returns results elif 'check network' in answer or 'network diagonostics' in answer: system.network_diagonistics() # runs a more in depth system diagonistic elif 'check system' in answer or 'system diagonostics' in answer: system.system_diagonistics() # runs all of my protocols, which are code that might not be convential elif 'run' in answer and 'protocol' in answer: protocolone = answer.replace('run ', '') userProtocol = protocolone protocol.runProtocol(mode, userProtocol) # The start of my project interface, a place that I store other projects related to cliff (I.E. hardware) elif 'create project' in answer: projectName = answer.split()[2:] system.createProject(mode, ' '.join(projectName)) # Allows C.L.I.F.F. to access the file system elif 'create file' in answer: answer = answer.replace('create file ', '') system.createFile(mode, answer) # Clears a file elif 'clear file' in answer: answer = answer.replace('clear file ', '') system.clearFile(mode, answer) # 'Writes to a file' elif 'write to file' in answer: answer = answer.replace('write to file ', '') system.writeFile(mode, answer) # deletes a file elif 'delete file' in answer: answer = answer.replace('delete file ', '') confirm = input('Delete file {}? (Y/N) '.format(answer)) confirm = confirm.lower() if confirm == 'y' or confirm == 'yes': try: os.remove(answer) except FileNotFoundError: textTesting(mode, 'File does not exist') else: textTesting(mode, 'File Removed') # allows cliff to fully autonomously run around the file system elif 'change directory to' in answer: directory = answer.replace('change directory to ', '') if directory == '..': currentdirectory = os.getcwd().split('/')[:-1] os.chdir('/'.join(currentdirectory)) else: os.chdir('{}/{}'.format(os.getcwd(), directory)) textTesting(mode, os.getcwd()) # reads whats in a file elif 'read file' in answer: answer = answer.replace('read file ', '') system.readFile(mode, answer) # opens a project elif 'open project' in answer: project = answer.replace('open project ', '') inProject = True projectName = project system.openProject(mode, project) # runs a command for the bash terminal elif 'run command' in answer: command = answer.replace('run command ', '') os.system(command) # closes out of a project elif 'close project' in answer: system.closeProject(mode) inProject = False # opens my notes elif 'open' in answer and 'notes' in answer: note = answer.replace('open ', '') note = note.replace('notes ', '') system.openNote( mode, '/home/connor/CLIFF/CLIFF/journals/notes/{}'.format(note)) # creates a note elif 'create' in answer and 'note' in answer: system.createNote(mode) elif 'list notes' in answer: system.listNotes(mode) elif 'delete note' in answer: note = answer.replace('delete note ', '') system.deleteNote(mode, note) elif 'run timer for ' in answer: time = answer.replace('run timer for ', '') system.timer(mode, time) else: textTesting( mode, 'I\'m sorry, we don\'t appear to have the command ' + answer) if inProject == False: lastCommand = answer return lastCommand, inProject, '' else: lastCommand = answer return lastCommand, inProject, projectName
def wincheck(move, computersMove): # Computes all possibilities if move is 'r' if move == 'r': # For paper: if computersMove == 'paper': textTesting(mode, 'You lose! Computer Chose Paper!') answer = inputTesting(mode, 'Play Again? (y,n): ') if answer == 'y': newmove = inputTesting( mode, 'rock, paper, or scissors? (r, p, s): ') newcomputersMove = random.choice(choices) wincheck(newmove, newcomputersMove) else: textTesting(mode, 'ok') # For Scissors: if computersMove == 'scissors': textTesting(mode, 'You won! Computer Chose Scissors!') answer = inputTesting(mode, 'Play Again? (y,n): ') if answer == 'y': newmove = inputTesting( mode, 'rock, paper, or scissors? (r, p, s): ') newcomputersMove = random.choice(choices) wincheck(newmove, newcomputersMove) else: textTesting(mode, 'ok') # For Rock: if computersMove == 'rock': textTesting(mode, 'Tie! Computer Chose rocks!') newmove = inputTesting( mode, 'rock, paper, or scissors? (r, p, s): ') newcomputersMove = random.choice(choices) wincheck(newmove, newcomputersMove) # Computes all possibilites for paper: elif move == 'p': # For Paper: if computersMove == 'paper': textTesting(mode, 'Tie! Computer Chose Paper!') newmove = inputTesting( mode, 'rock, paper, or scissors? (r, p, s): ') newcomputersMove = random.choice(choices) wincheck(newmove, newcomputersMove) # For Scissors: if computersMove == 'scissors': textTesting(mode, 'You lose! Computer Chose Scissors!') answer = inputTesting(mode, 'Play Again? (y,n): ') if answer == 'y': newmove = inputTesting( mode, 'rock, paper, or scissors? (r, p, s): ') newcomputersMove = random.choice(choices) wincheck(newmove, newcomputersMove) else: textTesting(mode, 'ok') # For Rock: if computersMove == 'rock': textTesting(mode, 'You win! Computer Chose rocks!') answer = inputTesting(mode, 'Play Again? (y,n): ') if answer == 'y': newmove = inputTesting( mode, 'rock, paper, or scissors? (r, p, s): ') newcomputersMove = random.choice(choices) wincheck(newmove, newcomputersMove) else: textTesting(mode, 'ok') # Computes all probabilities for scissors: elif move == 's': # For Paper if computersMove == 'paper': textTesting(mode, 'You Won! Computer Chose Paper!') answer = inputTesting(mode, 'Play Again? (y,n): ') if answer == 'y': newmove = inputTesting( mode, 'rock, paper, or scissors? (r, p, s): ') newcomputersMove = random.choice(choices) wincheck(newmove, newcomputersMove) else: textTesting(mode, 'ok') # For scissors if computersMove == 'scissors': textTesting(mode, 'Tie! Computer Chose Scissors!') newmove = inputTesting( mode, 'rock, paper, or scissors? (r, p, s): ') newcomputersMove = random.choice(choices) wincheck(newmove, newcomputersMove) # For Rock if computersMove == 'rock': textTesting(mode, 'You Lose! Computer Chose rocks!') answer = inputTesting(mode, 'Play Again? (y,n): ') if answer == 'y': newmove = inputTesting( mode, 'rock, paper, or scissors? (r, p, s)') newcomputersMove = random.choice(choices) wincheck(newmove, newcomputersMove) else: textTesting(mode, 'ok') else: textTesting(mode, 'That is not a move!') newmove = inputTesting(mode, 'rock, paper, or scissors? (r, p, s): ') newcomputersMove = random.choice(choices) wincheck(newmove, newcomputersMove)