28 lines
575 B
Python
28 lines
575 B
Python
import os
|
|
|
|
|
|
def get_data_id():
|
|
data_id_file = 'data_id.txt'
|
|
if not os.path.exists(data_id_file):
|
|
with open(data_id_file, 'w') as f:
|
|
idx = 0
|
|
f.write(f'{idx:0>15d}\n')
|
|
f.write(f'{idx:0>15d}\n')
|
|
with open(data_id_file, 'rb') as f:
|
|
f.seek(-16, 2)
|
|
s = f.read().decode()
|
|
idx = int(s)
|
|
print(idx)
|
|
|
|
return idx
|
|
|
|
|
|
def set_data_id(idx: int):
|
|
data_id_file = 'data_id.txt'
|
|
with open(data_id_file, 'a') as f:
|
|
f.write(f'{idx:0>15d}\n')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
get_data_id()
|