def fortune_app(environ, start_response): status = '200 OK' headers = [('Content-Type', 'text/plain; charset=utf-8')] start_response(status, headers) path = environ['PATH_INFO'] params = urllib.parse.parse_qs(environ['QUERY_STRING']) db = Simpledb('db.txt') if path == '/insert': db.insert(params['key'][0], params['value'][0]) return ['inserted'.encode()]
def application(environ, start_response): headers = [('Content-Type', 'text/plain; charset=utf-8')] path = environ['PATH_INFO'] params = urllib.parse.parse_qs(environ['QUERY_STRING']) db = Simpledb('db.txt') if path == '/insert': start_response('200 OK', headers) db.insert(params['key'][0], params['value'][0]) return ['Inserted'.encode()] elif path == '/select': s = db.select_one(params['key'][0]) start_response('200 OK', headers) if s: return [s.encode()] else: return ['NULL'.encode()] elif path == '/delete': start_response('200 OK', headers) d = db.delete(params['key'][0]) if d: return ['Deleted'.encode()] else: return ['NULL'.encode()] elif path == '/update': start_response('200 OK', headers) u = db.update(params['key'][0], params['value'][0]) if u: return ['Updated'.encode()] else: return ['NULL'.encode()] else: start_response('404 Not Found', headers) return ['Status 404: Resource not found'.encode()]
def application(environ, start_response): headers = [('Content-Type', 'text/plain; charset=utf-8')] path = environ['PATH_INFO'] params = urllib.parse.parse_qs(environ['QUERY_STRING']) #db = Simpledb('data.txt') if path == '/insert': start_response('200 OK', headers) params1 = params['key'][0] params2 = params['value'][0] Simpledb.add("data.txt", str(params1), int(params2)) return ["INSERTED".encode()] elif path == '/select': params1 = params['key'][0] print(params1) s = Simpledb.find("data.txt", str(params1)) start_response('200 OK', headers) if s != None: return ["RETRIEVED: ".encode() + str(s).encode()] else: return ['NULL'.encode()] elif path == '/delete': start_response('200 OK', headers) params1 = params['key'][0] s = Simpledb.delete("data.txt", str(params1)) return ["DELETED".encode()] elif path == '/update': params1 = params['key'][0] params2 = params['value'][0] Simpledb.update("data.txt", str(params1), int(params2)) start_response('200 OK', headers) return ["UPDATED".encode()] else: start_response('404 Not Found', headers) return ['Status 404: Resource not found'.encode()]
from database import Simpledb db = Simpledb('recipes.txt') def recipe(): print( 'What would you like to do: add, find, delete, update, print, or quit?' ) res = input().lower() if res.startswith('a'): print('Enter a recipe') key = input().upper() print('Enter the ingredients') value = input() db.insert(key, value) print('Info added') recipe() elif res.startswith('f'): print('Enter a recipe') key = input().upper() val = db.select_one(key) print(val) recipe() elif res.startswith('d'): print( 'Enter a recipe. If a message is not returned, there is no matching name in the directory.' ) key = input().upper() db.delete(key) recipe() elif res.startswith('u'):
from database import Simpledb book = open('phonebook.txt', 'a') book.close() print('Welcome to your Phone Book!') file = Simpledb('phonebook.txt') while True: status = 'whoa' while status != 'a' and status != 'f' and status != 'd' and status != 'u' and status != 'q': status = input( 'Select one of the following actions:\n\'a\' for Adding a new contact\n\'f\' for searching for an existing contact\n\'d\' for Deleting an existing contact\n\'u\' for updating an existing contact\n\'q\' for Exiting the program' ) if status == 'a': file.key = input('What is the person\'s name?') file.value = input('And their phone number?') file.insert() print('All done!') input('Press enter to continue:') elif status == 'f': file.key = input('What is the person\'s name?') print('Here is their phone number:') print(file.select_one()) input('Press enter to continue:') elif status == 'd': file.key = input('What is this person\'s name?') file.delete() print('Consider it done!') input('Press enter to continue:') elif status == 'u': file.key = input('What is this person\'s name?') file.value = input('What is this person\s new phone nubmer')
from database import Simpledb loop = True db = Simpledb('telephone.txt') db.__repr__() while loop == True: print( 'Would you like to:\n1:Delete a phone number?\n2:Update a phone number?\n3:Add another phone number?\n4:Find a phone number?\n5:Quit the program\nEnter a number 1-5' ) choice = input() while choice != '1' and choice != '2' and choice != '3' and choice != '4' and choice != '5': print('Please type 1, 2, 3, 4, or 5.') choice = input() if choice == '1' or choice == '2' or choice == '3' or choice == '4' or choice == '5': break if choice == '1': print('Whose number would you like deleted (enter a name)') name = input() db.delete(name) print('Number is deleted.') if choice == '2': print('Whose number would you like to update?') name = input() print('What number would you like to update with?') number = input() db.update(name, number) if choice == '3': print('What number would you like added?') number = input() print('Whose number is it?') name = input()
command = command.lower() #print (command) return command while True: command = commandUser() c = str(command) if (c == 'a'): key = input("Enter a name: ") key = key.lower() value = input("Enter the phone number(only enter digits): ") value = int(value) Simpledb.add("data.txt", key, value) elif (c == 'f'): key = input("Enter the name you would like to search for: ") key = key.lower() Simpledb.find("data.txt", key) elif (c == 'd'): key = input("Enter the name you would like to delete: ") key = key.lower() Simpledb.delete("data.txt", key) elif (c == 'u'): key = input("Enter the name you would like to search for: ") key = key.lower() Simpledb.update("data.txt", key)
print(''' Type 'a' to add to the directory. Type 'f' to find a name in the directory. Type 'd' to delete a name in the directory. Type 'u' to update a name in the directory. Type 'q' to quit. ''') print() choice = input('Choose an option from above:\n') # When the add command is entered, the user should be prompted twice, first for a name (spaces allowed) and second for a phone number. # The name and number should be entered into the database with the name as the key and the number as the value. if choice == 'a': key = input('Enter the name to be added: ') value = input('Enter ' + key.title() + "'s phone number: ") db.insert(key, value) # When the find command is entered, the user should be prompted for a name, which the program then searches for. # If the name is found, the number should be printed; if it is not found, a message should say so. elif choice == 'f': key = input('Enter the name to be found: ') num = db.select_one(key) if num != None: print(key.title() + "'s number is " + num) else: print(key.title() + ' is not in the directory') # When the delete command is entered, the user should be prompted for a name, which the program then searches for. # If the name is found, the name and the phone number should be deleted. If the name is not found, a message should say so. elif choice == 'd': key = input('Enter the name to be deleted: ')
def calls(choice): # If "a" is chosen, it will ask for a name and number to be added. if choice == 'a' or choice == 'A': name = input("What is the name of the person?") phonenumber = input("What is their number?") mydirectory = Simpledb(filename, name, phonenumber) mydirectory.insert() text = mydirectory.__repr__() print(text) print( "The text above shows the name, phonenumber, and filename that was added." ) # If "f" is chosen, it will ask for the name and see whether or not there is a phonenumber available to print. if choice == 'f' or choice == 'F': phonenumber = '' name = input( "What is the name of the person whose number you are trying to find?" ) v = Simpledb(filename, name, phonenumber) j = v.select_one() text = v.__repr__() if j == 'Not Found': print("Not found. We are sorry.") else: print(text) print( "Find Completed! We found the name with the number above in the file listed." ) # If "d" is chosen, it will ask for the name and decide whether or not it can be deleted. if choice == 'd' or choice == 'D': phonenumber = '' name = input( "What is the name of the person whose number you are trying to delete?" ) z = Simpledb(filename, name, phonenumber) j = z.delete() text = z.__repr__() if j == "Not Found!": print('Not found') else: print(text) print( 'Found and Deleted! We deleted this name and number from the file listed.' ) #If "u" is chosen, it will ask for the name and decide whether an updated number is possible or not. if choice == 'u' or choice == 'U': phonenumber = '' name = input( "What is the name of the person whose number you are trying to update?" ) v = Simpledb(filename, name, phonenumber) b = v.select_one() if b == "Not Found": print("Not found!") else: phonenumber = input("What is the new number of this person?") b = Simpledb(filename, name, phonenumber) b.update() text = b.__repr__() print(text) print( "Completed! It has been successfully updated with the new number " + phonenumber)
from database import Simpledb db = Simpledb("data.txt") file = open("data.txt", "w") file.close() while False == False: print("ENTER COMMAND(a, f, d, u, or q)!!!") command = input() if command == "a": print("Enter name") name = input() print("Enter phone number") number = input() db.add(name, number) elif command == "f": print("Enter name") name = input() db.find(name) elif command == "d": print("Enter name") name = input() db.delete(name) elif command == "u": print("Enter name") name = input() names = db.find(name) if names != None: print("Enter phone number") number = input() db.update(name, number) elif command == "q": break