def toJSON(self): return { "txId": self.txId, "txType": self.txType, "amount": self.amount, "username": getName(self.user), "recipientname": getName(self.recipient), "date": self.date.strftime(date_format) }
def __repr__(self): if self.txType == "Deposit": return "<Tx %s: Deposit $%d to %s>" %\ (self.txId or "", self.amount, getName(self.user, default="<deleted>")) elif self.txType == "Withdrawal": return "<Tx %s: Withdraw $%d from %s>" %\ (self.txId or "", self.amount, getName(self.user, default="<deleted>")) else: return "<Tx %s: Transfer $%d from %s to %s>" %\ (self.txId or "", self.amount, getName(self.user, default="<deleted>"), getName(self.recipient, default="<deleted>"))
def menu(): no_menu = True while no_menu: print("[1] Login") print("[2] Crear Cuenta") print("[3] Ver hilos") print("[0] Salir") opcion = utils.getNumber(4) if opcion == 1: user = input("Usuario: ") passs = input("Contraseña: ") token = utils.getToken(user, passs) if token != False: print("Bienvenido " + utils.getName(token)) no_menu = False else: print("Usuario/Contraseña Incorrectos") elif opcion == 2: user = input("Usuario: ") passs = input("Contraseña: ") name = input("Nombre: ") utils.Logon(user, passs, name) elif opcion == 3: print("Mostrar hilos") elif opcion == 0: print("Saliendo...") no_menu = False
def viewStudents(): # get parameters from request _uid = request.form.get('uid', type=str) _cid = request.form.get('cid', type=str) # connect to mysql conn = mysql.connect() cursor = conn.cursor() # validate course id cursor.execute('SELECT ctid FROM courses WHERE cid=%s', (_cid,)) data = cursor.fetchone() if len(data) == 0: cursor.close() conn.close() print('viewStudents <cid> not found!!') return json.dumps({}) # check if teacher id and course id match if _uid != data[0]: cursor.close() conn.close() print('viewStudents <cid> and <uid> not match!!') return json.dumps({}) # return student list cursor.execute('SELECT sid FROM rosters WHERE cid=%s', (_cid,)) data = cursor.fetchall() msg = [] for student in data: sid = student[0] sname = utils.getName(cursor, sid) msg.append([sid, sname]) cursor.close() conn.close() return json.dumps(msg)
def dealWithUnknownPerson(frame, face_encoding, top, left, bottom, right): cv2.rectangle(frame, (left * 4, top * 4), (right * 4, bottom * 4), (0, 255, 0), 3) cv2.imshow("Live Camera", frame) name = getName() addNewPerson(name, face_encoding.tolist()) update(face_encoding, name) if cv2.waitKey(1) == 13: return name
def moveData(data): chunk_id = utils.getName(data).zfill(4) utils.myprint('Moving chunck ' + chunk_id) utils.mymkdir(TMPDIR + chunk_id) utils.mycmd('cp ' + data + ' ' + TMPDIR) # utils.mycmd( 'tar --strip-components=7 -C ' + REF_TMPDIR + chunk_id + ' -xf '+ REF_TMPDIR + '/' + data.split('/')[-1] + ' --exclude \'*.txt\'' ) utils.mycmd('tar -C ' + TMPDIR + chunk_id + ' -xf ' + TMPDIR + data.split('/')[-1]) utils.mycmd('rm -r ' + TMPDIR + '/' + chunk_id + '/landmarks/') utils.mycmd('rm -r ' + TMPDIR + '/' + chunk_id + '/confidence/') if os.path.exists(TMPDIR + '/' + data.split('/')[-1]): utils.mycmd('rm ' + TMPDIR + '/' + data.split('/')[-1])
def __init__(self, horde, saved=None): self.horde = horde self.objects = {} self.asked = {} self.knownActions = {} self.knowledges = {} self.sante = [] if saved is None: self.name = utils.getName() self.knownActions["rester"]= petiteActionConnue("rester") self.age = 0 self.male = random.randint(0, 1)==0 self.forme = 1. self.action = "rester" self.accompagniedBy = [] else: #~ print saved #~ print saved["name"] self.name = saved["name"] for a in saved["knownActions"].values(): self.knownActions[a["name"]]= petiteActionConnue(a["name"], a) self.knowledges= saved["knowledges"] self.age = float(saved["age"]) self.sante = list(saved["sante"]) self.male = bool(saved["male"] ) #saved["male"] == "True" #~ print self.sante self.forme = float(saved["forme"]) self.action = saved["action"] self.accompagniedBy = list(saved["accompagniedBy"]) self.objects = saved["objects"]
def viewCourses(): # get parameters from request _id = request.form.get('id', type=str) # connect to mysql conn = mysql.connect() cursor = conn.cursor() # validate user id and get user type cursor.execute('SELECT utype FROM users WHERE id=%s', (_id,)) data = cursor.fetchone() if len(data) == 0: cursor.close() conn.close() print('viewCourses <id> not found!!') return json.dumps({}) user_type = data[0] if user_type == 'T': cursor.execute('SELECT * FROM courses WHERE ctid=%s', (_id,)) all_courses = cursor.fetchall() msg = utils.courses2dict(all_courses) elif user_type == 'S': # all courses cursor.execute('SELECT * FROM courses') all_courses = cursor.fetchall() msg = utils.courses2dict(all_courses) for cid in msg: msg[cid]['status'] = 'NULL' msg[cid]['cteacher'] = utils.getName(cursor, msg[cid]['ctid']) # active courses cursor.execute('SELECT cid FROM rosters WHERE sid=%s', (_id,)) all_active_courses = cursor.fetchall() for active_course in all_active_courses: msg[active_course[0]]['status'] = 'active' # completed courses cursor.execute('SELECT cid FROM pastrosters WHERE sid=%s', (_id,)) all_completed_courses = cursor.fetchall() for completed_course in all_completed_courses: msg[completed_course[0]]['status'] = 'completed' cursor.close() conn.close() return json.dumps(msg)
def menu(): primera_vez = True name = "Anonimo" no_menu = True token = False os.system("cls") while no_menu: print(" ______________________ ") print("|| ||") print("|| MENU PRINCIPAL ||") print("|| ||") print("|| [1] Login ||") print("|| [2] Crear Cuenta ||") print("|| [3] Ver hilos ||") print("|| [0] Salir ||") print("|| ||") print("||______________________||") opcion = utils.getNumber(0, 4, "Opción: ") if opcion == 1: os.system("cls") print("{### FORMULARIO LOGEO ###}") user = input("Usuario: ") passs = utils.keyAlmacenada(0, user, "") no_guardado = False if passs == None: no_guardado = True passs = input("Contraseña: ") token = utils.getToken(user, passs) if token != False: if no_guardado: utils.keyAlmacenada(1, user, passs) name = utils.getName(token) no_menu2 = True while no_menu2: if primera_vez: os.system("cls") print("Bienvenido " + name) primera_vez = False maxima = 2 os.system("cls") print(" ______________________ ") print("|| ||") print("|| LOGEADO ||") print("|| ||") print("|| [1] Ver hilos ||") if user != "Anonimo": print("|| [2] Nuevo hilo ||") maxima = 3 if name == "dios": print("|| [3] Borrar hilo ||") maxima = 4 print("|| [0] Salir ||") print("|| ||") print("||______________________||") opcion = utils.getNumber(0, maxima, "Opción: ") if opcion == 1: no_menu21 = True while no_menu21: os.system("cls") print( " ______________________________________________ " ) print("||\t\t\t\t\t\t||") print("||\t\tSELECCIONA EL HILO\t\t||") utils.getHilos() print("||\t\t[100] Volver\t\t\t||") print("||\t\t\t\t\t\t||") print( "||______________________________________________||" ) opcion = utils.getNumber(100, utils.cuenta_hilos, "ID Hilo: ") if opcion >= 101: no_menu4 = True while no_menu4: os.system("cls") print("Mostrando hilo " + str(opcion) + ": " + utils.hilos[opcion - 101]) print( " _______________________________________________________________________________ " ) print("||\t\t\t\t\t\t\t\t\t\t||") print("||\t\t\t\t\tHILOS\t\t\t\t\t||") utils.getComentarios(opcion) if (name == "dios"): print( "||\t\t\t\t[98] Borrar comentario\t\t\t\t||" ) if (name != "Anonimo"): print( "||\t\t\t\t[99] Añadir comentario\t\t\t\t||" ) print("||\t\t\t\t\t\t\t\t\t\t||") print("||\t\t\t\t[100] Volver\t\t\t\t\t||") print("||\t\t\t\t\t\t\t\t\t\t||") print( "||______________________________________________________________________________||" ) opcion2 = utils.getNumber( 98, 101, "Opcion: ") if opcion2 == 100: no_menu4 = False os.system("cls") elif opcion2 == 99: print("{### NUEVO COMENTARIO ###}") texto_comentario = input( "Texto del comentario: ") utils.setComentarioHilo( opcion, texto_comentario, name, token) elif opcion2 == 98: print("{### BORRAR COMENTARIO ###}") Id_comentario = utils.getNumber( 100, utils.cuenta_comentarios, "Id Comentario: ") utils.deleteComentarioHilo( opcion, Id_comentario, token) else: no_menu21 = False os.system("cls") elif opcion == 2: os.system("cls") print("Escribe 'Cancelar' para cancelar la accion.") print("{########~NUEVO HILO~########}") titulo_hilo = input("Nombre del hilo: ") if titulo_hilo != "Cancelar": utils.setHilo(name, titulo_hilo, token) elif opcion == 3: os.system("cls") print( " ______________________________________________") print("||\t\t\t\t\t\t||") print("||\t\tSELECCIONA EL HILO\t\t||") utils.getHilos() print("||\t\t\t\t\t\t||") print("||\t\t[100] Volver\t\t\t||") print("||\t\t\t\t\t\t||") print( "||______________________________________________||" ) id_hilo = utils.getNumber(100, utils.cuenta_hilos, "ID Hilo: ") if id_hilo != 100: utils.deleteHilo(id_hilo, token) else: no_menu2 = False os.system("cls") primera_vez = True name = "Anonimo" token = False else: print("Usuario/Contraseña Incorrectos") elif opcion == 2: no_pass = True os.system("cls") print("{### FORMULARIO REGISTRO ###}") user = input("Usuario: ") while no_pass: passs = input("Contraseña: ") repass = input("Introduzca de nuevo la contraseña: ") if passs == repass: no_pass = False else: print("Las contraseñas no coinciden") name = input("Nombre: ") utils.Logon(user, passs, name) elif opcion == 3: if primera_vez: os.system("cls") print("Has entrado como " + name) primera_vez = False no_menu3 = True while no_menu3: print(" ______________________________________________ ") print("||\t\t\t\t\t\t||") print("||\t\tSELECCIONA EL HILO\t\t||") utils.getHilos() print("||\t\t\t\t\t\t||") print("||\t\t[100] Volver\t\t\t||") print("||______________________________________________||") opcion = utils.getNumber(100, utils.cuenta_hilos, "Opción: ") if opcion != 100: no_menu31 = True while no_menu31: os.system("cls") print("Mostrando hilo " + str(opcion) + ": " + utils.hilos[opcion - 101]) print( " _______________________________________________________________________________ " ) print("||\t\t\t\t\t\t\t\t\t\t||") print("||\t\t\t\t\tHILOS\t\t\t\t\t||") utils.getComentarios(opcion) print("||\t\t\t\t\t\t\t\t\t\t||") print("||\t\t\t\t[100] Volver\t\t\t\t\t||") print("||\t\t\t\t\t\t\t\t\t\t||") print( "||______________________________________________________________________________||" ) opcion = utils.getNumber(100, 101, "Opción: ") if opcion == 100: os.system("cls") no_menu31 = False else: os.system("cls") no_menu3 = False primera_vez = True name = "Anonimo" elif opcion == 0: os.system("cls") print("Saliendo...") no_menu = False
if sys.argv[1] == "Dictionary": print(dictionary) if dictionary else print("") #output ecosystem/animal if sys.argv[1] == "Topic": if res: print(next(iter(res)).title()) if next(iter(res)) else print("") else: for s in content: words = s.split(' ') for word in words: word = word.translate(str.maketrans('', '', string.punctuation)) if utils.isTopic(word): print(word.title()) if word else print("") break #output name if sys.argv[1] == "Name": name = utils.getName(s) if name.strip(): print(name.title()) #output mindmap if sys.argv[1] == "Mindmap": map = utils.getMindMap(res) emptyMap = {"nodes": [], "links": []} if map != {"nodes": [], "links": []}: minmdap = json.dumps(map) print(minmdap) if minmdap else print("")