Exemple #1
0
def select(show_key, table, con_key):

    if table == "" or show_key == "":
        print("select需要输入参数")
    else:
        title = file_read(table)[0]
        suit_list = handle(table, con_key)
        if show_key == "*":
            show_key = ''
            for key in title:
                if show_key == '':
                    show_key = key
                else:
                    show_key = '%s,%s' % (show_key, key)
        else:
            pass

        if suit_list:
            show_list = show_key.strip().split(",")
            for line in suit_list:
                for show_name in show_list:
                    name_index = title.index(show_name.strip())
                    print(line[name_index], end="\t")
                print()
        print("查询到的条数:%s" % len(suit_list))
Exemple #2
0
def update(show_key, table, con_key):

    if table == "" or show_key == "":
        print("update需要输入参数")
    else:
        if "=" in show_key:
            show_list = show_key.strip().split("=")
            if show_list[0].strip() == "staff_id":
                exit("staff_id不允许改动")
            else:
                message = file_read(table)
                title = message[0]
                context = message[1]

                if show_list[0] == "phone":
                    if not show_list[1].isdigit() or len(show_list[1]) != 11 or [True for line in context if show_list[1] in line]:
                        exit("phone键值对冲突")
                    else:
                        pass
                else:
                    pass

                show_index = title.index(show_list[0].strip())
                suit_list = handle(table, con_key)

                for line in suit_list:
                    staff_index = int(line[0]) - 1
                    context[staff_index][show_index] = show_list[1].strip("\",\'")

                print("\033[32mupdate语句执行完成\033[0m")
                print("影响条数:\033[31m%s\033[0m" % len(suit_list))
                file_write(message, table)
        else:
            exit("update语句错误")
Exemple #3
0
def handle(table, con_key):
    message = file_read(table)
    title = message[0]
    context = message[1]
    suit_list = []
    if con_key:
        for var_value in ["age", "staff_id", "phone"]:
            if var_value in con_key:  # var_value 是否在con_key中
                var_index = title.index(var_value)  # var_value的位置
                key = var_value
                for line in context:  # line 文件内容循环
                    re_index = re.search(key,
                                         con_key).span()  # 查key在con_key中的位置
                    con_key_last = con_key[re_index[1]:].strip()  # 排除key后剩余值
                    key = line[var_index]  # key在line中的值
                    if "=" in con_key_last:
                        new_key_last = con_key_last.replace("=", "").strip()
                        con_key = "%s==%s" % (key, new_key_last)
                    else:
                        con_key = "%s%s" % (key, con_key_last)

                    if eval(con_key):
                        suit_list.append(line)
                break
        else:
            if "=" in con_key and "!" in con_key:
                contrast = "!="
            elif "=" in con_key and "!" not in con_key:
                contrast = "="
            elif "like" in con_key:
                contrast = "like"
            else:
                exit("条件无法判断")

            con_list = con_key.split(contrast)

            if len(con_list) == 2:
                key_index = title.index(con_list[0].strip())
                for line in context:
                    con_list[0] = line[key_index]
                    key = con_list[0].strip()
                    con_key_last = con_list[1].strip("\",\', ,\n")
                    if contrast == "like":
                        if con_key_last in key:
                            suit_list.append(line)
                    elif contrast == "=":
                        if key == con_key_last:
                            suit_list.append(line)
                    else:
                        if key != con_key_last:
                            suit_list.append(line)
            else:
                print("语句错误")

    else:
        suit_list = context

    return suit_list
Exemple #4
0
def create_map_files(number_of_map_files):
    contents = file_module.file_read(settings.ROOT_FOLDER /
                                     'some_city_names.txt',
                                     encoding='utf-8')
    for number in range(number_of_map_files):
        if len(list(settings.MAPS_FOLDER.iterdir())) > 20:
            break
        map_file = settings.MAPS_FOLDER / str(
            settings.MAP_FILE_FORMATTED.format(
                map_name=random.choice(contents)))
        map_file.touch()
Exemple #5
0
def uninstall(tablename):
    message = file_read(tablename)
    context = message[1]
    staff_id = input("输入staff_id值:").strip()
    if staff_id.isdigit():
        if 0 < int(staff_id) <= len(context):
            del_info = context[int(staff_id) - 1]
            context.remove(del_info)
            file_write(message, tablename)
            print("\033[31m staff_id: %s删除成功\033[0m" % staff_id)
        else:
            print("\033[41m staff_id超出范围\033[0m")
    else:
        print("\033[41m staff_id字符类型错误\033[0m")
Exemple #6
0
def users_reader(x):
    import file as f
    input_file = x
    user1r = f.file_read(input_file)
    p2 = []
    p4 = []
    p5 = []
    p6 = []
    p7 = []
    for data in user1r:
        p2.append(data)
    for i in range(len(p2)):
        p10, p11, p12, p13 = p2[int(i)].rstrip('\n').split(' ')
        p11 = str(p11).replace('_', ' ')
        p4.append(p10), p5.append(p11), p6.append(p12), p7.append(p13)
    return p4, p5, p6, p7
Exemple #7
0
def addition(tablename):
    userdate = []
    message = file_read(tablename)
    title = message[0]
    context = message[1]
    staff_id = len(context) + 1
    userdate.append(staff_id)
    for titlename in title[1:]:
        while True:
            info = input("%s:" % titlename).strip()
            if info:
                if titlename == "age" and not info.isdigit():
                    print("%s值不符,请重新输入" % titlename)
                    continue
                elif titlename == "phone":
                    if info.isdigit() and len(info) == 11:
                        if [True for line in context
                                if info in line]:  # info是否存在line中
                            print("phone值冲突")
                            continue
                        else:
                            pass
                    else:
                        print("%s值不符,请重新输入" % titlename)
                        continue

                userdate.append(info)
                break
            else:
                print("\033[31m%s is NULL\033[0m" % titlename)

    context.append(userdate)

    file_write(message, tablename)

    print("用户添加成功")
Exemple #8
0
import PySimpleGUI as sg
from file import file_read, file_write

fname = "Text.txt"

tasks = file_read(fname)

layout = [[sg.Text("ToDo List")],
          [
              sg.InputText("", key='todo_item'),
              sg.Button(button_text="Add", key='add_save')
          ],
          [
              sg.Listbox(values=tasks, size=(40, 10), key="items"),
              sg.Button("Delete"),
              sg.Button("Edit"),
              sg.Button("Exit")
          ]]

window = sg.Window("ToDo App", layout)
while True:
    events, values = window.Read()
    if events == 'add_save':
        tasks.append(values['todo_item'])
        window.FindElement('items').Update(values=tasks)
        window.FindElement('add_save').Update("Add")
        window.FindElement('todo_item').Update('')

    elif events == "Delete":
        tasks.remove(values["items"][0])
        window.FindElement('items').Update(values=tasks)
Exemple #9
0
 def __init__(self):
     """Contructor
 """
     self.data = file_read()
     self.data.file_read()