You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
958 B
36 lines
958 B
2 years ago
|
import pymysql
|
||
|
from pymysql.cursors import DictCursor
|
||
|
from data_dict import special_symbols, escape_list
|
||
|
|
||
|
db_config = {
|
||
|
"host": "192.168.66.101",
|
||
|
"user": "root",
|
||
|
"passwd": "Sxzgx1209",
|
||
|
"port": 3306,
|
||
|
'database': 'scrapy'
|
||
|
}
|
||
|
|
||
|
SELECT_SQL = "SELECT * FROM scrapyh s WHERE s.id = %s;"
|
||
|
|
||
|
|
||
|
class DbAction:
|
||
|
def __init__(self):
|
||
|
self.conn = pymysql.Connect(**db_config)
|
||
|
self.cursor = self.conn.cursor(cursor=DictCursor)
|
||
|
|
||
|
@staticmethod
|
||
|
def decode_pwd(_pwd):
|
||
|
for k, v in special_symbols.items():
|
||
|
if k in _pwd:
|
||
|
_pwd = _pwd.replace(k, v)
|
||
|
for item in escape_list:
|
||
|
if item[0] in _pwd:
|
||
|
_pwd = _pwd.replace(item[0], item[1])
|
||
|
return _pwd
|
||
|
|
||
|
def get_data_by_id(self, _id):
|
||
|
self.cursor.execute(SELECT_SQL, (_id,))
|
||
|
result = self.cursor.fetchone()
|
||
|
result['unzip_pwd'] = self.decode_pwd(result['unzip_pwd'])
|
||
|
return result
|