Пример #1
0
 def do_select(self, query):
     try:
         result_db = self.cur.execute(query)
     except Exception as e:
         LOG.error('查询命令错误', e)
         result_db = False
     return result_db
Пример #2
0
 def send_email(self, to_list, cc_list, sub=None, content=None, file_path=None, subtype='html'):
     msg = MIMEMultipart()
     if sub is None:
         msg['Subject'] = '无标题邮件'
     else:
         msg['Subject'] = sub
     msg['From'] = self._me
     msg['To'] = ";".join(to_list)
     msg['Cc'] = ";".join(cc_list)
     if content is None:
         puretext = MIMEText('该邮件未输入任何内容')
         msg.attach(puretext)
     else:
         puretext = MIMEText(content, _subtype=subtype, _charset='utf-8')
         msg.attach(puretext)
     if file_path is not None:
         for tuple_path in tuple(file_path):
             mail_file = MIMEApplication(open(tuple_path, 'rb').read())
             mail_file.add_header('Content-Disposition', 'attachment', filename='%s' % tuple_path.split('/')[-1])
             msg.attach(mail_file)
     try:
         self._server.sendmail(self._me, to_list, msg.as_string())
         return True
     except Exception as e:
         LOG.error(str(e))
         return False
Пример #3
0
 def delete(self, k):
     tag = self.r.exists(k)
     # 判断这个key是否存在,相对于get到这个key他只是传回一个存在火灾不存在的信息,
     # 而不用将整个k值传过来(如果k里面存的东西比较多,那么传输很耗时)
     if tag:
         self.r.delete(k)
     else:
         LOG.error('这个key不存在')
Пример #4
0
 def do_update(self, query):
     """
     update和delete\insert
     :param query:
     :return:
     """
     try:
         result_db = self.cur.execute(query)
         self.commit()
     except Exception as e:
         LOG.error('查询命令错误', e)
         result_db = False
     return result_db
Пример #5
0
 def __init__(self):
     conf = ConfigOperate('DB_config')
     self.host = conf.get_config('mysql_conf', 'host')
     self.port = int(conf.get_config('mysql_conf', 'port'))
     self.user = conf.get_config('mysql_conf', 'username')
     self.passwd = conf.get_config('mysql_conf', 'password')
     try:
         self.conn = pymysql.connect(host=self.host,
                                     port=self.port,
                                     user=self.user,
                                     passwd=self.passwd)
         self.cur = self.conn.cursor()
     except Exception as e:
         LOG.error('数据库连接错误', e)
Пример #6
0
 def __init__(self, ip, password, port=6379, db=1):  # 构造函数
     try:
         self.r = redis.Redis(host=ip, password=password, port=port, db=db)  # 连接redis固定方法,这里的值必须固定写死
     except Exception as e:
         LOG.error('redis连接失败,错误信息%s' % e)