This repository has been archived on 2026-08-27. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
RequestCounter/bin/tests/init_db.py
T

30 lines
952 B
Python
Raw Normal View History

2022-02-08 19:46:11 +08:00
#!/usr/bin/env python3
# -- coding:utf-8 --
# @Author: markushammered@gmail.com
# @Development Tool: PyCharm
# @Create Time: 2022/2/5
# @File Name: init_db.py
import os
import sqlite3
import sys
if __name__ == '__main__':
while True:
yes_or_no = input('该操作会将数据库初始化输入y继续:')
if yes_or_no == 'y':
2022-02-19 10:45:00 +08:00
try:
2022-02-19 11:27:13 +08:00
os.remove('../db/count.db')
2022-02-19 10:45:00 +08:00
except PermissionError:
print('有其他程序正在使用此数据库无法删除')
sys.exit(-1)
2022-02-19 11:27:13 +08:00
conn = sqlite3.connect('../db/count.db')
2022-02-08 19:46:11 +08:00
cursor = conn.cursor()
cursor.execute('create table ReqCount (name text primary key, times integer )')
sys.exit(0)
elif yes_or_no == 'n':
print('已取消')
sys.exit(0)
else:
print('请输入y继续或n退出')
continue