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():
|
2023-11-17 21:34:22 +08:00
|
|
|
try:
|
2023-11-18 11:51:58 +08:00
|
|
|
lock.acquire(True)
|
2023-11-17 21:34:22 +08:00
|
|
|
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
|
2023-11-17 21:34:22 +08:00
|
|
|
order by PYInitial
|
|
|
|
'''
|
|
|
|
cursor.execute(sql)
|
|
|
|
result = cursor.fetchall()
|
2023-11-18 11:51:58 +08:00
|
|
|
finally:
|
|
|
|
lock.release()
|
2023-11-17 21:34:22 +08:00
|
|
|
# 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()
|