def readindatalst(filename):
    ######################## 读入已有数据
    ff = open(filename, 'r')
    lst = [eval(i1.replace('\n', '')) for i1 in ff]
    ff.close()
    ########
    timekeylst = []
    for dicti in lst:
        print('saveddata---', dicti.keys())
        for keyi in dicti.keys():
            timekeylst.append(keyi)
    print(len(lst))
    return lst, timekeylst
   #^^^^^^^END

def savedatalst(filename, newdatadict):
    ######## 保存数据
    olddata, oldtimekey = readindatalst(filename)
    for keyi in newdatadict:
        newtimekey = keyi
        datacontent = str(newdatadict[keyi][0])
    ######## 生成唯一化的数据
    dlst2 = []
    for i1 in olddata:
        dlst2.append(str(list(i1.values())[0][0]))
    dlstin1 = list(set(dlst2))
    ########
    print('#'*50)
    if newtimekey not in oldtimekey \
            and datacontent not in dlstin1:
        ff = open(filename, 'a', encoding='utf-8')
        print(newdatadict, file=ff)
        ff.close()
        print('savein--->', newtimekey)
    else:
        print('dataexist')
   #^^^^^^^END
