Created
February 18, 2024 08:07
-
-
Save damnever/2f5519b0c5753e005a9f15b0b51d1973 to your computer and use it in GitHub Desktop.
Synchronize the date and time of some recording devices (MRECSET.TXT)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
MRECSET_TXT = 'MRECSET.TXT' | |
ENCODING = 'GB18030' | |
datetime_now = datetime.now().strftime("%H:%M %Y/%m/%d") | |
updated_lines = [] | |
with open(MRECSET_TXT, 'rb') as file: # encoding='GB18030' | |
for line in file: | |
if line.startswith(b'TIME:'): | |
line = line.replace(line[5:len(datetime_now)+5], datetime_now.encode(ENCODING)) | |
updated_lines.append(line) | |
content = b''.join(updated_lines) | |
with open(MRECSET_TXT, 'wb') as file: | |
file.write(content) | |
print(f"Datetime updated:\n{content.decode(ENCODING)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment