def boxValidation(self, address, host, userName): """Confirm no mailbox data is empty""" messages = common.empty("Address", address) messages += common.empty("Host", host) messages += common.empty("User name", userName) return messages
def siteValidation(self, name, endpoint, identifier, address): """Confirm no site data is empty""" messages = common.empty("Name", name) messages += common.empty("Endpoint", endpoint) messages += common.empty("Identifier", identifier) messages += common.empty("Address", address) return messages
def find_user(username, password): if empty(username): raise ValueError('username must be provided') if empty(password): raise ValueError('password must be provided') cur = g.db.execute( "SELECT id, username FROM users WHERE username = ? AND password = ?", [username, password]) row = cur.fetchone() if not row: return None return User(row)
def create_todo(user_id, description): if user_id is None: raise ValueError('user_id must be provided') if empty(description): raise ValueError('description must be provided') g.db.execute( "INSERT INTO todos (user_id, description, completed) VALUES (?, ?, ?)", [user_id, description, 0]) g.db.commit()
def renameSiteValidation(self, newName, oldName): """ """ messages = "" if newName != oldName: messages = common.empty("Name", newName) messages += common.notExists(newName, self.sites) else: messages = "Name not changed" return messages
def read_excel(self): excel_data = self.mdb.excels.find({'status': 0}) ii = 0 for excel in excel_data: ii = ii + 1 excel_file = requests.get(excel['path'], stream=True) download = self.download_excel(excel['path']) if download['status']: workbook = xlrd.open_workbook(download['file_path']) table = workbook.sheet_by_index(0) fileds = [] for k, v in enumerate(table.row_values(0)): if v in config.field_map: fileds.append(config.field_map.get(v)) for index in range(1, table.nrows): print('*' * 20, ii, '#', index) new_row = table.row_values(index) if common.empty(new_row): break else: new_data = dict(zip(fileds, new_row)) #初始化状态 new_data['update_status'] = 0 self.saveData(new_data, excel) del new_data, new_row #消费过后变状态 self.mdb.excels.update({'_id': excel.get('_id')}, {'$set': { 'status': 1 }}) else: print(download['msg']) pass