first commit

main
roger_home_pc 1 year ago
commit 240e8e56bf
  1. 35
      db.py

35
db.py

@ -0,0 +1,35 @@
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
Loading…
Cancel
Save