构建项目 初始化提交
完成了籍贯学号crud的核心api 存储采用ini
This commit is contained in:
commit
32e3ac6f66
16
com/native/entity/entity.py
Normal file
16
com/native/entity/entity.py
Normal file
@ -0,0 +1,16 @@
|
||||
###########################################################################################
|
||||
# Author: dongl
|
||||
# Time: 2022/11/01 15:39
|
||||
# version: 1.0
|
||||
###########################################################################################
|
||||
# 学生类结构体
|
||||
###########################################################################################
|
||||
|
||||
|
||||
class Student(object):
|
||||
def __init__(self, sid, name, native):
|
||||
self.sid = sid
|
||||
self.name = name
|
||||
self.native = native
|
||||
|
||||
|
0
com/native/gui/__init__.py
Normal file
0
com/native/gui/__init__.py
Normal file
17
com/native/main/main.py
Normal file
17
com/native/main/main.py
Normal file
@ -0,0 +1,17 @@
|
||||
###########################################################################################
|
||||
# Author: dongl
|
||||
# Time: 2022/11/01 15:39
|
||||
# version: 1.0
|
||||
###########################################################################################
|
||||
|
||||
from com.native.entity import entity
|
||||
from com.native.parser.parser_core import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
a = entity.Student("22100919", "某某某", "黑龙省")
|
||||
inster(a)
|
||||
#
|
||||
# queryInfoBySid('22100915')
|
||||
# queryInfoBySid("某某")
|
||||
|
||||
# delete('22100916')
|
143
com/native/parser/parser_core.py
Normal file
143
com/native/parser/parser_core.py
Normal file
@ -0,0 +1,143 @@
|
||||
###########################################################################################
|
||||
# Author: dongl
|
||||
# Time: 2022/11/01 15:39
|
||||
# version: 1.0
|
||||
###########################################################################################
|
||||
import configparser
|
||||
import this
|
||||
|
||||
from com.native.entity import entity
|
||||
|
||||
config = configparser.ConfigParser() # 类实例化
|
||||
config_indexes = configparser.ConfigParser() # 类实例化
|
||||
config_name_sid = configparser.ConfigParser() # 类实例化
|
||||
# 定义文件路径
|
||||
path = r'../../../resources/native.ini'
|
||||
path_indexes = r'../../../resources/native_indexes.ini'
|
||||
path_name_sid = r'../../../resources/name_sid_indexs.ini'
|
||||
|
||||
config.read(path, encoding="utf-8")
|
||||
config_indexes.read(path_indexes, encoding="utf-8")
|
||||
config_name_sid.read(path_name_sid, encoding="utf-8")
|
||||
|
||||
|
||||
def queryInfoBySid(sid):
|
||||
try:
|
||||
value = config.items(sid)
|
||||
print(f"[sid:{sid}] :", value)
|
||||
except:
|
||||
print(f"sid【{sid}】不存在")
|
||||
return False
|
||||
return value
|
||||
|
||||
|
||||
def queryInfoByName(name):
|
||||
sid = config_name_sid.get("name_sid", name)
|
||||
sid_info = config.items(sid)
|
||||
print(f"[{name}] -> {sid_info}")
|
||||
return sid_info
|
||||
|
||||
|
||||
def queryAllInfoByNative(native):
|
||||
sid_index = config_indexes.get(native, "sid_index")
|
||||
sid_list = sid_index.split(",")
|
||||
for sid in sid_list:
|
||||
print(f"native[{native}] ---> {config.items(sid)}")
|
||||
|
||||
|
||||
def updeteStu(student):
|
||||
try:
|
||||
config.set(student.sid, "name", student.name)
|
||||
config.set(student.sid, "native", student.native)
|
||||
except:
|
||||
print(f"sid【{student.sid}】不存在")
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def inster(student):
|
||||
# native 写入
|
||||
try:
|
||||
config.add_section(student.sid)
|
||||
config.set(student.sid, "sid", student.sid)
|
||||
config.set(student.sid, "name", student.name)
|
||||
config.set(student.sid, "native", student.native)
|
||||
except:
|
||||
print(f"sid【{student.sid}】已存在")
|
||||
return False
|
||||
config.write(open(path, 'w+', encoding="utf-8")) # 将修改写入到配置文件
|
||||
|
||||
# name_sid 写入
|
||||
try:
|
||||
config_name_sid.get("name_sid", student.name)
|
||||
name_sid = config_name_sid.get("name_sid", student.name)
|
||||
name_sid = name_sid + "," + student.sid + ","
|
||||
config_name_sid.set("name_sid", student.name, name_sid)
|
||||
print(f"name -> sid 重名: {student.name} : {student.sid}")
|
||||
except configparser.NoOptionError:
|
||||
config_name_sid.set("name_sid", student.name, student.sid)
|
||||
print(f"name -> sid : {student.name} : {student.sid}")
|
||||
except configparser.NoSectionError:
|
||||
print("***********************************************************")
|
||||
print("致命错误 ---> resources/name_sid_indexs.ini 可能找不到或遭到破坏")
|
||||
print("***********************************************************")
|
||||
print("原始结构为: ")
|
||||
print("[name_sid]")
|
||||
return
|
||||
|
||||
config_name_sid.write(open(path_name_sid, 'w+', encoding="utf-8")) # 将修改写入到配置文件
|
||||
|
||||
# native_indexes 写入
|
||||
try:
|
||||
config_indexes.add_section(student.native)
|
||||
config_indexes.set(student.native, "sid_index", student.sid + ",")
|
||||
print(f"籍贯地区【{student.native}】未记录 ---> 初始化该地区以及学号")
|
||||
except:
|
||||
print(f"籍贯地区【{student.native}】已存在 ---> 继续添加该地区下学号")
|
||||
sid_index = config_indexes.get(student.native, "sid_index")
|
||||
sid_index = sid_index + student.sid + ","
|
||||
config_indexes.set(student.native, "sid_index", sid_index)
|
||||
config_indexes.write(open(path_indexes, 'w+', encoding="utf-8")) # 将修改写入到配置文件
|
||||
|
||||
|
||||
def delete(key):
|
||||
#################################
|
||||
# 删除 native_indexes 下的学号索引
|
||||
# 按学号查信息
|
||||
print(config.items(key))
|
||||
name = config.get(key, 'name')
|
||||
native = config.get(key, "native")
|
||||
|
||||
# 该籍贯包含的学号
|
||||
sid_indexes = config_indexes.get(native, "sid_index")
|
||||
sid_list = sid_indexes.split(",")
|
||||
|
||||
this.remove_sid_index = 0
|
||||
for i, sid in enumerate(sid_list):
|
||||
if sid == key:
|
||||
# 删除native_indexes sid
|
||||
sid_list.remove(sid)
|
||||
continue
|
||||
|
||||
# 新sid_list
|
||||
new_list = ''
|
||||
for sid in sid_list:
|
||||
new_list += sid + ','
|
||||
|
||||
config_indexes.set(native, "sid_index", new_list)
|
||||
|
||||
####################################################
|
||||
# 删除 name_sid 下的索引
|
||||
config_name_sid.remove_option("name_sid", name)
|
||||
|
||||
##################################
|
||||
# 删除 native 下的学号
|
||||
if not config.remove_section(key):
|
||||
print(f"sid【{key}】不存在")
|
||||
return False
|
||||
|
||||
config.write(open(path, 'w+', encoding="utf-8")) # 将修改写入到配置文件
|
||||
config_indexes.write(open(path_indexes, 'w+', encoding="utf-8")) # 将修改写入到配置文件
|
||||
config_name_sid.write(open(path_name_sid, 'w+', encoding="utf-8")) # 将修改写入到配置文件
|
||||
print(f'sid:{key}【已删除】')
|
||||
return True
|
0
com/native/view/__init__.py
Normal file
0
com/native/view/__init__.py
Normal file
0
resources/management.log
Normal file
0
resources/management.log
Normal file
4
resources/name_sid_indexs.ini
Normal file
4
resources/name_sid_indexs.ini
Normal file
@ -0,0 +1,4 @@
|
||||
[name_sid]
|
||||
某某 = 22100917,22100918,
|
||||
某某某 = 22100919
|
||||
|
15
resources/native.ini
Normal file
15
resources/native.ini
Normal file
@ -0,0 +1,15 @@
|
||||
[22100917]
|
||||
sid = 22100917
|
||||
name = 某某
|
||||
native = 黑龙省
|
||||
|
||||
[22100918]
|
||||
sid = 22100918
|
||||
name = 某某
|
||||
native = 黑龙省
|
||||
|
||||
[22100919]
|
||||
sid = 22100919
|
||||
name = 某某某
|
||||
native = 黑龙省
|
||||
|
3
resources/native_indexes.ini
Normal file
3
resources/native_indexes.ini
Normal file
@ -0,0 +1,3 @@
|
||||
[黑龙省]
|
||||
sid_index = 22100917,22100918,22100919,
|
||||
|
Loading…
x
Reference in New Issue
Block a user