def check_local_status() ->dict: '''check someone who with token''' sql = "select username,token from user where token is not NULL or username = '******' order by id desc limit 0,1" ret = sqlite_db.select(sql,just_first=True) if not ret['status']: logging.error(ret['msg']) return ret.get('records',dict())
def get_notes(username='******', is_del='0'): ''' 查询当前用户的笔记 :param filename: sqlite3文件名 :param username: 用户名 :param is_del: 是否删除,默认为否 :return: list of dict 异常直接返回空列表 ''' try: table = 'msg' filter_list = [['username', '=', username], ['is_del', '=', is_del]] if is_del == 'all': filter_list.pop() sql = be_sql().sel_sql(table, filter_list=filter_list) # print(sql) ret = sqlite_db.select(sql) if ret['status']: for record in ret['records']: record['message'] = decrypt_text(record['message'], 'message', user_name=username) record['detail'] = decrypt_text(record['detail'], 'detail', user_name=username) except Exception as e: logging.error(e) return ret
def get_user_info(table, username): filter_list = [['username', '=', username]] sql = be_sql().sel_sql(table, filter_list=filter_list) ret = sqlite_db.select(sql) if not ret['status']: logging.error(ret['msg']) info = ret['records'] if 'records' in ret.keys() else list() return info
def check_login_status(): ''' 查找 本地 token非空的人 :return: 查询结果 结构[[{'username':'','token':''}],] 无查询结果时 结构为[] ''' table = 'user' need_col_list = ['username', 'token'] filter_list = [['token', 'is not', 'NULL']] sql = be_sql().sel_sql(table, need_col_list, filter_list) logging.warning('sql_lite {}'.format(sqlite_db)) return sqlite_db.select(sql, just_first=True)
def get_notes(username='******', is_del='0'): sql = "select * from Msg where username = ? and is_del = 0" ret = sqlite_db.select(sql, [username]) # 解密 for note in ret.get('records', list()): note['message'] = decrypt_text(note['message'], 'message', username=username) note['detail'] = decrypt_text(note['detail'], 'detail', username=username) return ret
def add_notes(data): for k, v in data.items(): if 'username' != k: ele = k data[k] = cryptograph_text(v, k, username=data['username']) sql = "insert into Msg({},username) values(?,?)".format(ele) ret = sqlite_db.transaction(sql, [data[ele], data['usename']]) if not ret['status']: logging.error("message:{}\nsql:{}".format(ret['msg'], ret['errorsql'])) sql = "select * from Msg where username = ? and is_del = 0 order by id desc limit 0 ,1" ret = sqlite_db.select(sql, [data['username']], just_first=True) return ret
def send_Email_slot(self): ''' 获取序号对应的数据,打开窗口 :return: ''' msg_id = re.findall('\d+', self.sender().objectName())[0] sql = 'select message,detail from Msg where id = %s' % msg_id ret = sqlite_db.select(sql) if not ret['status']: logging.error(ret['msg']) info = ret['records'][0] if 'records' in ret.keys() else { 'message': 'untitle', 'detail': 'input text' } # info={'message':'test','detail':'123456'} #debug 使用 email_dlg = Ui_Email_Dialog(self, info) email_dlg.show()
def mail(info, title, recipients, content): # 获取授权密码 sql = "select * from email_settings where username ='******'" % info['username'] ret = sqlite_db.select(sql) if not ret['status']: logging.error(ret['msg']) records = ret['records'] if 'records' in ret.keys() else list() record, password = records[0], records[0]['password'] # ssl 端口设置 port = 25 if record['user_ssl'] == 1: port = record['ssl_port'] ret = {'status': 1, 'msg': ''} try: msg = MIMEText(content, 'plain', 'utf-8') # 括号里的对应发件人邮箱昵称、发件人邮箱账号 msg['From'] = formataddr([record['sender_name'], info['addr']]) msg['To'] = ','.join([recipients]) # 括号里的对应收件人邮箱昵称、收件人邮箱账号 msg['Subject'] = title # 邮件的主题,也可以说是标题 # server_offer = re.findall('@(.+?)\.',info['addr']) if port != 25: server = smtplib.SMTP_SSL("smtp.%s" % info['addr'].split('@')[-1], port) # 发件人邮箱中的SMTP服务器,端口是25 server.login(info['addr'], password) # 括号中对应的是发件人邮箱账号、邮箱密码 server.sendmail(info['addr'], msg['To'].split(','), msg.as_string()) # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件 server.quit() except Exception as e: logging.warning(str(e.smtp_error, encoding='gbk')) ret = { 'status': -1, 'msg': '账号%s %s' % (info['addr'], str(e.smtp_error, encoding='gbk')) } return ret
def get_user_reminder_conf(username): sql = """ select * from reminder where username=? order by sequence; """ return sqlite_db.select(sql, [username])
def get_email_conf(sql): print(sql) return sqlite_db.select(sql)
def get_user_email_conf(username, *args, **kwargs): sql = """ select * from email_settings where username=?; """ return sqlite_db.select(sql, [username], *args, **kwargs)