83 lines
2.0 KiB
Python
83 lines
2.0 KiB
Python
import re
|
|
import pymysql
|
|
|
|
class All_Setting():
|
|
def __init__(self,host,port,db):
|
|
self.host = host
|
|
self.port = port
|
|
self.db = db
|
|
|
|
def remove_symbols(self,text):
|
|
pattern = re.compile(r'[^\w\s]')
|
|
return pattern.sub('', text)
|
|
|
|
def get_chinese(self,text,printTxt=False):
|
|
pattern = r'[^\w\s]'
|
|
result = re.sub(pattern, '', text)
|
|
if printTxt:
|
|
print(result)
|
|
return result
|
|
|
|
def get_shoppingmalls(self,sql):
|
|
conn = pymysql.connect(
|
|
host= self.host,
|
|
port=self.port,
|
|
user='root',
|
|
password='Aliyun@7646!',
|
|
db=self.db,
|
|
charset='utf8mb4'
|
|
)
|
|
if conn:
|
|
print('ok')
|
|
cursor = conn.cursor()
|
|
cursor.execute(sql)
|
|
return cursor.fetchall()
|
|
|
|
def write_data(self,sql,data):
|
|
conn = pymysql.connect(
|
|
host= self.host,
|
|
port=self.port,
|
|
user='root',
|
|
password='Aliyun@7646!',
|
|
db=self.db,
|
|
charset='utf8mb4'
|
|
)
|
|
if conn:
|
|
print("连接成功!")
|
|
cursor = conn.cursor()
|
|
cursor.executemany(sql,data)
|
|
conn.commit()
|
|
cursor.close()
|
|
|
|
def update_data(self,sql):
|
|
conn = pymysql.connect(
|
|
host= self.host,
|
|
port=self.port,
|
|
user='root',
|
|
password='Aliyun@7646!',
|
|
db=self.db,
|
|
charset='utf8mb4'
|
|
)
|
|
if conn:
|
|
print("连接成功!")
|
|
cursor = conn.cursor()
|
|
cursor.execute(sql)
|
|
conn.commit()
|
|
cursor.close()
|
|
|
|
def write_data_one(self,sql,data):
|
|
conn = pymysql.connect(
|
|
host= self.host,
|
|
port=self.port,
|
|
user='root',
|
|
password='Aliyun@7646!',
|
|
db=self.db,
|
|
charset='utf8mb4'
|
|
)
|
|
if conn:
|
|
print("连接成功!")
|
|
cursor = conn.cursor()
|
|
cursor.execute(sql,data)
|
|
conn.commit()
|
|
cursor.close()
|