WeChatMsg/app/DataBase/micro_msg.py

53 lines
1.2 KiB
Python
Raw Normal View History

2023-11-15 21:57:29 +08:00
import os.path
2023-11-12 21:51:33 +08:00
import sqlite3
2023-11-18 11:51:58 +08:00
import threading
2023-11-12 21:51:33 +08:00
2023-11-18 11:51:58 +08:00
lock = threading.Lock()
2023-11-15 21:57:29 +08:00
DB = None
cursor = None
micromsg_path = "./app/Database/Msg/MicroMsg.db"
if os.path.exists(micromsg_path):
DB = sqlite3.connect(micromsg_path, check_same_thread=False)
# '''创建游标'''
cursor = DB.cursor()
2023-11-16 00:13:49 +08:00
def init_database():
global DB
global cursor
if not DB:
if os.path.exists(micromsg_path):
DB = sqlite3.connect(micromsg_path, check_same_thread=False)
# '''创建游标'''
cursor = DB.cursor()
2023-11-15 21:57:29 +08:00
def is_database_exist():
return os.path.exists(micromsg_path)
2023-11-12 21:51:33 +08:00
def get_contact():
try:
2023-11-18 11:51:58 +08:00
lock.acquire(True)
sql = '''select UserName,Alias,Type,Remark,NickName,PYInitial,RemarkPYInitial,ContactHeadImgUrl.smallHeadImgUrl,ContactHeadImgUrl.bigHeadImgUrl
from Contact inner join ContactHeadImgUrl on Contact.UserName = ContactHeadImgUrl.usrName
2023-11-18 14:55:41 +08:00
where Type%2=1 and Alias is not null
order by PYInitial
'''
cursor.execute(sql)
result = cursor.fetchall()
2023-11-18 11:51:58 +08:00
finally:
lock.release()
# DB.commit()
2023-11-12 21:51:33 +08:00
return result
2023-11-16 23:16:38 +08:00
def close():
global DB
if DB:
DB.close()
2023-11-12 21:51:33 +08:00
if __name__ == '__main__':
get_contact()