更改包路径

This commit is contained in:
MarkusJoe
2022-02-19 11:27:13 +08:00
parent fcb4c41f8e
commit 8c89f4a024
8 files changed
+33 -34

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env python3
# -- coding:utf-8 --
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2022/2/4
# @File Name: __init__.py.py
import os
from bin.utils.logger import logger
if not os.path.exists('./db/count.db'):
logger.error('未检测到用户计数数据库')
import sqlite3
conn = sqlite3.connect('./bin/db/count.db', check_same_thread=False)
cursor = conn.cursor()
cursor.execute('create table ReqCount (name text primary key, times int)')
conn.commit()
cursor.close()
conn.close()
logger.info('已在./db 目录下创建了count.db数据库')
BIN
View File
Binary file not shown.
+116
View File
@@ -0,0 +1,116 @@
#!/usr/bin/env python3
# -- coding:utf-8 --
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2022/2/4
# @File Name: sqlite.py
import sqlite3
from typing import Any
def insert_data(name: str) -> None:
"""
插入数据
:param name:
:return:
"""
conn = sqlite3.connect('./bin/db/count.db', check_same_thread=False)
cursor = conn.cursor()
try:
cursor.execute('insert into ReqCount values(?, ?)', (name, 1))
conn.commit()
finally:
cursor.close()
conn.close()
def fetch_data(name: str) -> int:
"""
获取数据
:param name:
:return:
"""
conn = sqlite3.connect('./bin/db/count.db', check_same_thread=False)
cursor = conn.cursor()
try:
cursor.execute('select * from ReqCount')
conn.commit()
data = cursor.fetchall()
temp_dict = {}
for k, v in data: # 遍历数据将元组数据转换为字典类型
temp_dict.setdefault(k, []).append(v)
for i, c in zip(temp_dict.keys(), temp_dict.values()):
temp_dict[i] = c[0]
if name in temp_dict.keys():
count = temp_dict[name] # 获取原数字 为 整型
update_data(name, count)
return count
else:
# 新建用户数据
insert_data(name)
return 0
finally:
cursor.close()
conn.close()
def update_data(name: str, times: int) -> None:
"""
更新数据
:param name:
:param times:
:return:
"""
conn = sqlite3.connect('./bin/db/count.db', check_same_thread=False)
cursor = conn.cursor()
try:
times += 1
cursor.execute('update ReqCount set times=? where name=?', (times, name))
conn.commit()
finally:
cursor.close()
conn.close()
def fetch_table() -> list:
"""
返回已有主题列表
:return:
"""
conn_temp = sqlite3.connect('./bin/db/style.db', check_same_thread=False)
cursor_temp = conn_temp.cursor()
try:
lst = []
cursor_temp.execute("select * from sqlite_master where type='table'")
for i in cursor_temp.fetchall():
lst.append(i[1])
return lst
finally:
cursor_temp.close()
conn_temp.close()
def fetch_style_data(style: str) -> list[dict[str, Any]]:
"""
获取主题数据库内的数据
:param style:
:return:
"""
conn = sqlite3.connect('./bin/db/style.db', check_same_thread=False)
cursor = conn.cursor()
try:
cursor.execute('select * from %(style_name)s' % {'style_name': style})
data = cursor.fetchall()
data_set = []
for i in data:
data_set.append({'index': i[0], 'base64': i[1], 'width': i[2], 'height': i[3]})
return data_set
finally:
cursor.close()
conn.close()
__all__ = ['fetch_table', 'fetch_data', 'fetch_style_data', 'update_data', 'insert_data']
+2 -2
View File
@@ -14,11 +14,11 @@ if __name__ == '__main__':
yes_or_no = input('该操作会将数据库初始化输入y继续:')
if yes_or_no == 'y':
try:
os.remove('../../db/count.db')
os.remove('../db/count.db')
except PermissionError:
print('有其他程序正在使用此数据库无法删除')
sys.exit(-1)
conn = sqlite3.connect('../../db/count.db')
conn = sqlite3.connect('../db/count.db')
cursor = conn.cursor()
cursor.execute('create table ReqCount (name text primary key, times integer )')
sys.exit(0)
+1 -1
View File
@@ -9,7 +9,7 @@
from typing import Optional
from flask import jsonify
from flask import Response
from db.sqlite import (update_data, fetch_table)
from bin.db import (update_data, fetch_table)
class ErrorProcess:
+2 -3
View File
@@ -6,10 +6,9 @@
# @File Name: view.py
import sqlite3
from flask import render_template
from db.sqlite import fetch_style_data
from db.sqlite import fetch_table
from bin.db import fetch_style_data
from bin.db import fetch_table
def view_template(style: str, length: int, name: str, count: str) -> str or tuple[bool, str]: