WeChatMsg/app/DataBase/micro_msg.py

58 lines
1.6 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
import time
2023-11-12 21:51:33 +08:00
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:
sql = '''select UserName,Alias,Type,Remark,NickName,PYInitial,RemarkPYInitial,ContactHeadImgUrl.smallHeadImgUrl,ContactHeadImgUrl.bigHeadImgUrl
from Contact inner join ContactHeadImgUrl on Contact.UserName = ContactHeadImgUrl.usrName
where Type=3 and Alias is not null
order by PYInitial
'''
cursor.execute(sql)
result = cursor.fetchall()
except:
time.sleep(0.2)
sql = '''select UserName,Alias,Type,Remark,NickName,PYInitial,RemarkPYInitial,ContactHeadImgUrl.smallHeadImgUrl,ContactHeadImgUrl.bigHeadImgUrl
from Contact inner join ContactHeadImgUrl on Contact.UserName = ContactHeadImgUrl.usrName
where Type=3 and Alias is not null
order by PYInitial
'''
cursor.execute(sql)
result = cursor.fetchall()
# 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()