def reset_password(): try: email = request.json['email'] code = request.json['code'] password = request.json['password'] temp_user = user_dao.get_by_email(email) if temp_user is None: return jsonify('User with this email doesn\'t exists!'), 400 else: user = temp_user.serialize temp_pr = password_reset_dao.get(user['id']) if temp_pr is None: return jsonify('No password reset request for this user!'), 400 else: pr = temp_pr.serialize if pr['code'] == code: # Encypt password encrypted_password = bcrypt_sha256.encrypt(password) temp_user.password = encrypted_password user_dao.update(temp_user) password_reset_dao.delete(temp_pr) return jsonify('Password reset successful!'), 202 else: return jsonify('Invalid verification code!'), 400 except KeyError as ke: passwordreset_sessionDB.rollback() return jsonify('Attribute ' + ke.args[0] + ' missing!'), 400
def run(): while True: print "开始处理任务" task = dao.select(state=0) cv.acquire() while task == None: cond_wait(cv) cv.release() ret = dao.update(state=1, update_time=now(), id=task.id) if ret == 0: print "任务已经被处理,直接跳出循环" continue page = http_crawler(task.link,task.type) if task.type == 0: print "处理列表任务...." for item in page: prefix = "http://yue.ifeng.com/news/detail_" link = prefix + item[0] new_task = build_task(link) dao.insert(new_task) cond_signal(cv) dao.update(state=2, update_time=now(), id=task.id) if task.type == 1: file_name = task.link.split("/")[-1] print "保存页面....",task.link,file_name save_page(page,file_name) ret = dao.update(state=2, update_time=now(), id=task.id) print "任务完成"
def zeroAllItems(items, type): for item in dao.getDicts( dao.getItemsToZero([item["name"] for item in items], type)): item["nominal"] = 0 item["min_val"] = 0 dao.update(item)
def editarUsuario(self, index, user): data = UserView.register_user(defaults=[user.nome, user.idade, user.telefone]) if not data: return nome, idade, telefone = data user.nome = nome user.idade = idade user.telefone = telefone table, dict = user.toDict() update(table, dict, user.id)
def distribute(itemsToDistribute, targetNominal, targetMag, targetAmmo, flags): itemsToDistribute = dao.getDicts(itemsToDistribute) numElements = calculateNumElements(itemsToDistribute) nominalPerElement = targetNominal / numElements if numElements != 0 else 0 setValues(nominalPerElement, itemsToDistribute) for item in itemsToDistribute: dao.update(item) if flags[0] == 1: distributeLinkedItem(itemsToDistribute, targetAmmo, "ammo") if flags[1] == 1: distributeLinkedItem(itemsToDistribute, targetMag, "mag")
def updateSel(self, multiplier=None): for element in self.tree.selection(): val = self.getEditedValues(element) val["name"] = self.tree.item(element)["text"] if multiplier is not None: val["nominal"] = val["nominal"] * multiplier val["min"] = val["min"] * multiplier dao.update(val) rows = dao.reExecuteLastQuery() self.updateDisplay(rows) try: self.treeview_sort_column(self.tree, self.sorted, self.reverse) except Exception: pass self.changed = True self.activatedFields.clear() self.refreshSubtypes()
def appendTypesToDatabase(xml, root, mod, useNew): count = 0 successes = [] message = " Items where added to database, duplicate items where not added:\n" items = xmlParser.parseFromString(xml, mod) params = xmlParser.createStringFromKeys(items[0]) itemVal = xmlParser.createValues(items) matches = xmlParser.gunsAndMatchingItem(items) if len(itemVal) > 100: sleep(1) i = 0 for item in items: item = item.parameters name = item["name"] err = dao.insertItem(params, list(item.values())) if err == 1: message += name + "\n" if useNew: item["rarity"] = dao.getRarity(name) item["mod"] = mod item["usage"] = itemVal[i][15:28] item["tier"] = itemVal[i][28:32] item["subtype"] = dao.getSubtype(name) dao.update(item) else: count += 1 successes.append(item["name"]) i += 1 if len(itemVal) > 100: sleep(1) if len(matches) != 0: dao.createCombos(matches) showError(root, "Success", str(count) + message) return successes
def distributeLinkedItem(guns, targetCount, type): zeroAllItems(guns, type) elementCount = 0 allItems = dao.getDicts(dao.getType(type)) for gun in guns: elementCount += int(gun["nominal"]) linkedItemsToGun = dao.getDicts( dao.getWeaponAndCorresponding(gun["name"])) matchingItems = getLinkedOfType(linkedItemsToGun, type) # If Multiple item types linked: multiple Mags for example, then the sum of nominals should equal the nominal # of gun for matchingItem in matchingItems: for item in allItems: if matchingItem["name"] == item["name"]: item["nominal"] += gun["nominal"] / len(matchingItems) perUnit = targetCount / elementCount if elementCount != 0 else 0 for item in allItems: item["nominal"] = int(ceil(item["nominal"] * perUnit)) item["min"] = int(ceil(item["nominal"] / 2)) dao.update(item)
deleteTestDb() print("Checking creating test user db...") assert (dao.create("CREATE TABLE IF NOT EXISTS test(id int, name varchar(64))", test_user_db) == True) assert (len(dao.select("SELECT * FROM test", test_user_db, False)) == 0) print("Checking insert test user db...") assert (dao.insert("INSERT INTO test(id, name) VALUES(?,?)", [123, "taro"], test_user_db) == True) assert (len(dao.select("SELECT * FROM test", test_user_db, False)) == 1) print("Checking update test user db...") assert (dao.update("UPDATE test SET name=? WHERE id=?", ["goro", 123], test_user_db) == True) assert (len(dao.select("SELECT * FROM test", test_user_db, False)) == 1) assert (dao.select("SELECT * FROM test", test_user_db, False)[0][1] == "goro") print("Checking delete a column test test db...") assert (dao.delete("DELETE FROM test WHERE id=?", [123], test_user_db) == True) assert (len(dao.select("SELECT * FROM test", test_user_db, False)) == 0) print("Checking insert user provisionally into test user db...") assert (dao.insertProvisionalUser2Db("name_test_1", "*****@*****.**", "123abc456def", "oneTimePassforUserEmailComfirm", test_user_db) == True) assert (dao.insertProvisionalUser2Db("name_test_2", "*****@*****.**", "123abc456def", "oneTimePassforUserEmailComfirm2",