2023-11-15 22:32:11 +08:00
|
|
|
import os.path
|
|
|
|
import sqlite3
|
2023-11-17 21:34:22 +08:00
|
|
|
import threading
|
2023-11-29 23:41:02 +08:00
|
|
|
import time
|
2023-11-15 22:32:11 +08:00
|
|
|
|
2023-11-17 21:34:22 +08:00
|
|
|
lock = threading.Lock()
|
2023-11-15 22:32:11 +08:00
|
|
|
DB = None
|
|
|
|
cursor = None
|
2023-11-29 21:23:44 +08:00
|
|
|
db_path = "./app/Database/Msg/Misc.db"
|
2023-11-15 22:32:11 +08:00
|
|
|
# misc_path = './Msg/Misc.db'
|
2023-11-29 21:23:44 +08:00
|
|
|
if os.path.exists(db_path):
|
|
|
|
DB = sqlite3.connect(db_path, check_same_thread=False)
|
2023-11-15 22:32:11 +08:00
|
|
|
# '''创建游标'''
|
|
|
|
cursor = DB.cursor()
|
|
|
|
|
|
|
|
|
2023-11-19 14:01:34 +08:00
|
|
|
def init_database():
|
|
|
|
global DB
|
|
|
|
global cursor
|
|
|
|
if not DB:
|
2023-11-29 21:23:44 +08:00
|
|
|
if os.path.exists(db_path):
|
|
|
|
DB = sqlite3.connect(db_path, check_same_thread=False)
|
2023-11-19 14:01:34 +08:00
|
|
|
# '''创建游标'''
|
|
|
|
cursor = DB.cursor()
|
|
|
|
|
|
|
|
|
2023-11-15 22:32:11 +08:00
|
|
|
def get_avatar_buffer(userName):
|
|
|
|
sql = '''
|
|
|
|
select smallHeadBuf
|
|
|
|
from ContactHeadImg1
|
|
|
|
where usrName=?;
|
|
|
|
'''
|
2023-11-17 21:34:22 +08:00
|
|
|
try:
|
|
|
|
lock.acquire(True)
|
2023-11-19 14:01:34 +08:00
|
|
|
try:
|
|
|
|
cursor.execute(sql, [userName])
|
2023-11-29 23:41:02 +08:00
|
|
|
except:
|
|
|
|
time.sleep(0.5)
|
2023-11-19 14:01:34 +08:00
|
|
|
init_database()
|
|
|
|
finally:
|
|
|
|
cursor.execute(sql, [userName])
|
2023-11-17 21:34:22 +08:00
|
|
|
result = cursor.fetchall()
|
|
|
|
# print(result[0][0])
|
|
|
|
if result:
|
|
|
|
return result[0][0]
|
|
|
|
finally:
|
|
|
|
lock.release()
|
2023-11-15 22:32:11 +08:00
|
|
|
return None
|
|
|
|
|
|
|
|
|
2023-11-29 23:41:02 +08:00
|
|
|
def close():
|
|
|
|
global DB
|
|
|
|
if DB:
|
|
|
|
DB.close()
|
|
|
|
|
|
|
|
|
2023-11-15 22:32:11 +08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
get_avatar_buffer('wxid_al2oan01b6fn11')
|