def test_crud(): company = Company() session.add(company) assert [] == crud.object_list(session, company, MyModel) obj = crud.create(session, company, MyModel, name='xxx') assert obj.name == 'xxx' session.commit() read_obj = crud.read(session, company, MyModel, obj.id) assert read_obj == obj assert 1 == crud.object_count(session, company, MyModel) assert [read_obj] == crud.object_list(session, company, MyModel) crud.update(session, company, MyModel, obj.id, name='aaa') session.commit() update_obj = crud.read(session, company, MyModel, obj.id) assert update_obj.name == 'aaa' crud.delete(session, company, MyModel, obj.id) delete_obj = crud.read(session, company, MyModel, obj.id) assert delete_obj is None assert 0 == crud.object_count(session, company, MyModel)
def user_del(): id = request.args.get("id") table = request.args.get("table") delete(table, id) users = inquire(table) flash(u"删除成功") return render_template("user.html", users=users, table=table)
def main(): while True: print(":=="*20) print("\t\tCONSOLE CRUD WITH SQLITE3") print(":=="*20) print("[C]REATE NEW DATABASE") print("[D]ROP DATABASE") print("[U]SE DATABASE") print("[E]xit") print(":=="*20) try: opt = input('Select one option:\n') if opt.upper() == 'C': crud.clear() db.createDB() elif opt.upper() == 'D': db.dropDB() elif opt.upper() == 'U': while True: print("[1] Insert new record") print("[2] Show all records") print("[3] Update a record") print("[4] Delete a record") print("[5] Search a record") print("[6] Exit") print(":=="*20) try: option = int(input('Select a option:\n')) if option == 1: crud.clear() crud.create() if option == 2: crud.clear() crud.get() if option == 3: crud.update() elif option == 4: crud.delete() elif option == 6: crud.clear() break except: print('Option invalid!') elif opt.upper() == 'E': break except: print('Option invalid!')
def removerUsuario(arguments): cpf = arguments['cpf'] where = "cpf = '" + str(cpf) + "'" crud.delete("login", where) retorno = crud.select("*", "login", "cpf = '" + cpf + "'") if len(retorno) == 0: naoExiste = { 'cpf': "removido", 'username': "", 'password': "", 'category': "" } return naoExiste return retorno[0]
def entry(): req = {} if request.method == 'POST': req = request.json crud.create(req["message"]) return req if request.method == 'GET': req = request.json retrive = crud.retrive(req["message"]) return retrive if request.method == 'PUT': req = request.json update = crud.update(req["_id"], req["message"]) return update if request.method == 'DELETE': req = request.json crud.delete(req["message"]) return req return req
def removerIngresso(arguments): codigo = arguments['codigo'] where = "codigo = " + str(codigo) crud.delete("ingresso", where) ingresso = crud.select("*", "ingresso", where) if len(ingresso) == 0: reply = { 'codigo': int(-1), 'nome': "", 'quantidade': int(-1), 'horarioInicio': "", 'horarioTermino': "", 'data': "", 'endereco': "", 'preco': float(-1) } return reply return ingresso[0]
def delete(id): crud.delete(id) response = jsonify(message="Carro excluido") response.headers.add("Access-Control-Allow-Origin", "*") return response
def delete_entity(resource, entity_id): resource_class = get_resource_class(resource) return crud.delete(resource_class, entity_id)
choice = input( "Enter the number of the operation you would like to perform: ") if choice == "1": website_to_create = input( "\nEnter the website for which you want the password to be created: " ) password_to_create = input("Enter the password: "******"2": website_to_read = input("\nEnter the name of the website: ") read(website_to_read) elif choice == "3": website_to_update = input( "\nEnter the website for which you want the password to be updated: " ) password_to_update = input("Enter the new password: "******"4": website_to_delete = input( "\nEnter the website for which you want the password to be deleted: " ) delete(website_to_delete) elif choice == "5": print("Goodbye!") quit() else: print("Wrong username or password.") quit()
import crud from pprint import pprint print '-'*80 print 'BEGIN Testing storage.MySQL.crud...' crud = crud.Crud('store_test') crud.query('SELECT * FROM session_data') crud.insert('session_data', [('key1', 'val1', 'str', 'sess1', 1234567890), ('key1', 'val1', 'str', 'sess1', 1234567890), ('key1', 'val1', 'str', 'sess1', 1234567890)]) crud.insert('session_data2', [('key1', 'val1', 'str', 'sess1', 1234567890), ('key1', 'val1', 'str', 'sess1', 1234567890), ('key1', 'val1', 'str', 'sess1', 1234567890)]) pprint(crud.get('session_data', {'session_id2=': "'sess1'", '`key`=': "'key2'"})) pprint(crud.get('session_data', {'session_id=': "'sess1'", '`key`=': "'key2'"})) crud.delete('session_data2') crud.delete('session_data') crud.insert('session_data', data=[('key2', 'val1', 'str', 'sess1', 1234567890)]) crud.drop_tables() crud.create_tables() crud.insert('session_data', data=[('key2', 'val1', 'str', 'sess1', 1234567890)]) crud.update('session_data2', data={'value': 'val3'}, conditions=[{'session_id=': "'sess1'"}, {'utime=':str(1234567890)}]) crud.update('session_data', data={'value': 'val3'}, conditions=[{'session_id=': "'sess1'"}, {'utime=':str(1234567890)}]) print 'END Testing storage.MySQL.crud...' print '-'*80
inner_decision2 = crud.take_decision() while inner_decision2 not in range(1, 8) or None: if inner_decision2 is None: print("{}There is no option like that!{}".format( colors["red_txt_black_bgr"], colors["white_txt"])) inner_decision2 = crud.take_decision() if inner_decision2 == 1: crud.create() elif inner_decision2 == 2: crud.print_data() elif inner_decision2 == 3: crud.update() elif inner_decision2 == 4: crud.delete() elif inner_decision2 == 5: crud.count_age() elif inner_decision2 == 6: crud.count_gender() elif inner_decision2 == 7: skipFirst = False secondMenu = False else: print( "{}There was an error with loading a data file!{}".format( colors["red_txt_black_bgr"], colors["white_txt"])) if inner_decision == 2 and not secondMenu: break
async def delete(iD: str): response = crud.delete(iD) return {"deleted": response}
def update(): CChis = [] res = [] details = [] Municipio = "" Casos = "" Tasa = "" datos = urllib.request.urlopen( 'http://coronavirus.saludchiapas.gob.mx/casos-por-municipio').read( ).decode() soup = BeautifulSoup(datos) os.system("cls") ################################################## Detalles de Chiapas tags = soup.find_all('h5', class_='card-title') for itemC in tags: num = itemC.get_text() CChis.append({'num': num}) ################################################## Historial table = soup.find('table', class_='table') for fila in table.find_all("tr"): #if nroFila==2: nroCelda = 0 for celda in fila.find_all('td'): if nroCelda == 0: Municipio = celda.text #print("Municipios:", Municipio) if nroCelda == 1: Casos = celda.text #print("Casos:", Casos) if nroCelda == 2: Tasa = celda.text res.append({ 'Municipio': Municipio, 'Casos': Casos, 'Tasa': Tasa }) #print("Tasa", Tasa) nroCelda = nroCelda + 1 #nroFila=nroFila+1 if len(crud.read('History')) == len(res): print("No hay cambios") else: for itemD in crud.read('ActualChis'): crud.delete('ActualChis', itemD) for item in CChis: crud.create('ActualChis', item) for itemD in crud.read('History'): crud.delete('History', itemD) for itemN in res: crud.create('History', itemN) print('Datos actualizados con exito') return 'Datos Actualizados'
#INSERINDO dados do BD #sequencia: id, cpf, nome, nascimento, endereco, cidade, estado values = [ "DEFAULT, '12345678911', 'joão pedro', '2019-03-05', 'R teste BD', 'python', 'ND'", "DEFAULT, '12345678956', 'karem rodrigues', '2019-03-05', 'R teste BD', 'python', 'ND'" ] tabela = 'alunos' crud.insert(values, tabela, cursor, conn) print(crud.select("*", 'alunos', cursor)) ############################################# #ATUALIZANDO dados do BD #sequencia: tabela, sets, cursor, conexao, where(se existir) crud.update("alunos", { "nome": "Deidata Naruto", "cidade": "Aldeia da Folha" }, cursor, conn, "id_aluno = 2") print(crud.select("*", 'alunos', cursor, "id_aluno = 2")) ############################################ #APAGANDO dados do BD #sequencia: tabela, where, cursor, conexao crud.delete("alunos", "cidade = 'Conceição do Ouros'", cursor, conn) print(crud.select( "*", 'alunos', cursor, ))
def delete_quote(id): if request.method == 'DELETE': return crud.delete(id)