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()]
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']) print(params) db = Simpledb('db.txt') if path == '/insert': db.add(params["key"][0], params["value"][0]) start_response('200 OK', headers) return ["Inserted".encode()] elif path == '/select': s = db.find(params['key'][0]) start_response('200 OK', headers) if s: return [s.encode()] else: return ['NULL'.encode()] elif path == '/delete': s = db.delete(params["key"][0]) start_response('200 OK', headers) if s: return ["Deleted".encode()] else: return ['NULL'.encode()] elif path == '/update': s = db.update(params["key"][0], params["value"][0]) start_response('200 OK', headers) if s: return ["Updated".encode()] else: return ['NULL'.encode()] else: start_response('404 Not Found', headers) return ['Status 404: Resource not found'.encode()]
'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() db.add(name, number) if choice == '4': print('Whose number is it?') name = input() db.find(name) if choice == '5': loop = False
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)