def deleteData(self): sql = 'delete from care_carolie_item ' \ 'where bool_consume is null' self.cursor.execute(sql) self.connect.commit() logs.info('成功删除%s数据' % self.cursor.rowcount)
def selectData(self): sql = 'select * from care_carolie_item' self.cursor.execute(sql) for i in self.cursor.fetchall(): print(i) logs.info('成功查询%s数据' % self.cursor.rowcount)
def main(self, parent_ip): # 查询数据 logs.info('查询shop_id为%s的科室' % parent_ip) data = self.selectData(parent_ip) # 写入到Excel表格 logs.info('写入到excel表格') w = WriteExcel() w.writeExcel(data) w.closeExcel()
def __init__(self, sec_name): r = ReadConfig() self.conf = r.getValue(sec_name) self.connect = pymysql.Connect(host=self.conf['url'], port=self.conf['port'], user=str(self.conf['username']), passwd=str(self.conf['password']), db=self.conf['db'], charset='utf8') self.cursor = self.connect.cursor() logs.info('成功连接数据库')
def main(self): self.deleteData() data = ReadExcel('Sheet1').data count = 0 for i in range(len(data)): self.insertData(data[i][0], data[i][1]) count += 1 # print(data[i][0], data[i][1]) logs.info('成功插入%s条数据', count) self.cursor.close() self.connect.close() logs.info('关闭数据库')
def selectData(self, parent_id): # 执行查询语句 sql = 'select shop_name, shop_id from es_shop where parent_id = "%s"' self.cursor.execute(sql % parent_id) # 将结果字典化 url = r'http://m.wdklian.com/care/apk/care.user?type=BIND_PART&no=%s' office_dict = {} for i in self.cursor.fetchall(): office_dict[i[0]] = url % i[1] # 关闭游标 self.connect.commit() logs.info('查询完成') return office_dict
def __init__(self, sec_name): mysql = ReadYaml(mysql_path) # 读取mysql配置文件 self.mysql_conf = mysql.getValue(sec_name) # 获取mysql的数据 self.connect = pymysql.Connect( host = self.mysql_conf['url'], port = self.mysql_conf['port'], user = str(self.mysql_conf['username']), passwd = str(self.mysql_conf['password']), db = self.mysql_conf['db'], charset = 'utf8' ) self.cursor = self.connect.cursor() logs.info('成功连接数据库')
def writeExcel(self, data=None): self.worksheet.write(0, 0, '科室名') self.worksheet.write(0, 1, '二维码') logs.info('创建表格') # 判断是否有值 if data != None: # 写入科室名 self.worksheet.write_column('A2', list(data.keys())) logs.info('科室名写入完成') for i in range(len(list(data.values()))): # 形成二维码 MakeQRCode(list(data.values())[i]) # 写入二维码 num = 'B' + str(i + 1) self.worksheet.insert_image(num, image_path) logs.info('二维码写入完成')
def driverClose(self): self.driver.close() logs.info('关闭浏览器')
def __init__(self, url): self.driver = webdriver.Chrome() self.driver.get(url) logs.info('启动浏览器')