Skip to content

Instantly share code, notes, and snippets.

@damnever
Created February 18, 2024 08:07
Show Gist options
  • Save damnever/2f5519b0c5753e005a9f15b0b51d1973 to your computer and use it in GitHub Desktop.
Save damnever/2f5519b0c5753e005a9f15b0b51d1973 to your computer and use it in GitHub Desktop.
Synchronize the date and time of some recording devices (MRECSET.TXT)
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