def append_history(item, path='history.clh', mode='a', check_exist=True): from my_constant import config from my_coding import my_encode myclan = item.clan if item else None import tkinter.messagebox """ :param item: History instance :param path: file path :param mode: file open mode :param check_exist: :return: None """ if mode == 'clear': with open(path, mode='w', encoding=config['write']): pass return elif not item: return elif check_exist: if item.date in myclan.h: return with open(path, mode=mode, encoding=config['write']) as f: f.write('###') f.write(item.date + '\n') f.write(item.name + '\n') f.write(item.kuni + '\n') f.write(str(item.ninsuu) + '\n') f.write(str(item.kekka[0]) + ' ' + str(item.kekka[1]) + ' ' +\ str(item.percent[0]) + ' ' + str(item.percent[1])+'\n') for i in range(item.ninsuu): f.write(item.mikata[i].abbr + my_encode(item.mikata[i].hslv[item.date])\ + my_encode(item.teki[i]) + '\n') for i in item.rekishi: f.write(i[0] + my_encode(i[1]) + my_encode(i[2])\ + str(i[3]) + str(i[4]) + '\n') if check_exist==True: tkinter.messagebox.showinfo('保存成功!', '已保存至' + path)
def append_donate(item, path='data.cpd', mode='a', check_exist=True): from my_constant import config from my_coding import my_encode if item: myclan = item.clan import tkinter.messagebox """ :param item: Donate Item instance :param path: file path :param mode: file open mode :param check_exist: :return: None """ if mode == 'clear': with open(path, 'w', encoding=config['write']): pass return elif not item: return elif check_exist: if item.date in myclan.d: return with open(path, mode=mode, encoding=config['write']) as f: f.write('###') f.write(item.date + '\n') for i in item.donateList: f.write(i[0] + ' ' + str(i[1][0]) + ' ') if len(i[1][1]): for j in i[1][1]: f.write(my_encode(j[0]) + my_encode(j[1]) + my_encode(j[2])\ + my_encode(j[3]) + str(j[4]) + str(j[5]) + '-'\ + str(j[6]) + '+') f.write('|') if len(i[1][2]): for j in i[1][2]: f.write(my_encode(j[0]) + my_encode(j[1]) + my_encode(j[2])\ + my_encode(j[3]) + str(j[4]) + str(j[5]) + '-'\ + str(j[6]) + '+') f.write('\n') if check_exist==True: tkinter.messagebox.showinfo('保存成功!', '已保存至' + path)