Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d7c2f2a7c | |||
| b9323ff938 | |||
| ec6d59dc5d |
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
**/__pycache__
|
||||
**/*.db
|
||||
**/*.sql
|
||||
db/*
|
||||
0
linux/main.py
Normal file
0
linux/main.py
Normal file
6
packages/python_tcp_to_sqlite.py
Normal file
6
packages/python_tcp_to_sqlite.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import os, sys
|
||||
|
||||
def select_sqlite_dir():
|
||||
print("请选择你的sqlite数据库保存路径", "(默认存储路径为.\\tts\\sqlite\\db)")
|
||||
sqlite_dir = input()
|
||||
print(f"{sqlite_dir}")
|
||||
3
windows/command/help.py
Normal file
3
windows/command/help.py
Normal file
@@ -0,0 +1,3 @@
|
||||
print("dir", "{:8}选择你需要存放数据库的位置".format(" "))
|
||||
print("list", "{:7}查看你需要存放数据库的位置".format(" "))
|
||||
print("init", "{:7}初始化数据库配置".format(" "))
|
||||
44
windows/command/init.py
Normal file
44
windows/command/init.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# 初始化命令脚本
|
||||
import sqlite3
|
||||
import os
|
||||
import shutil
|
||||
|
||||
# 初始化生成路径
|
||||
# 确定当前路径
|
||||
dir_path = os.path.dirname(os.path.abspath(__file__))
|
||||
# 确定sqlite数据库初始位置
|
||||
db_path = os.path.dirname(os.path.dirname(dir_path))
|
||||
# 删除db文件夹
|
||||
shutil.rmtree(f'{db_path}\\db')
|
||||
|
||||
# 建立初始化db文件夹存放数据库
|
||||
os.mkdir(f'{db_path}\\db')
|
||||
|
||||
print(db_path)
|
||||
# 建立sqlite数据库
|
||||
conn = sqlite3.connect(f'{db_path}\\db\\admin.db')
|
||||
# 建立管理员表
|
||||
create_table = """CREATE TABLE admin(
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
passwd TEXT NOT NULL
|
||||
)"""
|
||||
conn.execute(create_table)
|
||||
conn.commit()
|
||||
|
||||
# 写入初始管理员名字和密码
|
||||
print("请输入您的管理员名字")
|
||||
admin_name = input()
|
||||
print("请输入您的管理员名字")
|
||||
admin_passwd = input()
|
||||
# 配置写入数据库表单
|
||||
INSERTE_SQL = f"INSERT INTO admin (name, passwd) VALUES ('{admin_name}', '{admin_passwd}');"
|
||||
conn.execute(INSERTE_SQL)
|
||||
conn.commit()
|
||||
|
||||
# 列出您输入的管理员名字和密码
|
||||
# 暂时没想好怎么写
|
||||
# 正常的应该是读取数据库再输出,因为太晚了,先随便谢谢凑合
|
||||
print('名字', f'{admin_name}')
|
||||
print('密码', f'{admin_passwd}')
|
||||
conn.close()
|
||||
10
windows/command/select_sqlite_dir.py
Normal file
10
windows/command/select_sqlite_dir.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import os
|
||||
import sys
|
||||
# 导入当前目录下的packages包到环境变量
|
||||
# 获取当前位置绝对路径
|
||||
dir_path = (os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.append(os.path.join(dir_path, '../../'))
|
||||
from packages import python_tcp_to_sqlite as tts
|
||||
|
||||
# 选择你需要存放数据库的位置
|
||||
tts.select_sqlite_dir()
|
||||
30
windows/main.py
Normal file
30
windows/main.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# 调用py脚本的主程序
|
||||
# 引入库
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 设定
|
||||
if len(sys.argv) > 1:
|
||||
subprocess.run("python.exe .\\command\\help.py", shell=True)
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
command = sys.argv[1]
|
||||
|
||||
if command == "help":
|
||||
subprocess.run("python.exe .\\command\\help.py", shell=True)
|
||||
|
||||
elif command == "dir":
|
||||
subprocess.run("python.exe .\\command\\select_sqlite_dir.py", shell=True)
|
||||
|
||||
elif command == "list":
|
||||
subprocess.run("dir", shell=True)
|
||||
|
||||
elif command == "init":
|
||||
subprocess.run("python.exe .\\command\\init.py", shell=True)
|
||||
|
||||
else:
|
||||
print(f"未知的命令: {command}")
|
||||
else:
|
||||
print("tcp_to_sqlite", "v0.01")
|
||||
print("输入 help ", "可以查看支持命令")
|
||||
Reference in New Issue
Block a user