-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_dates.py
More file actions
executable file
·33 lines (21 loc) · 1.06 KB
/
set_dates.py
File metadata and controls
executable file
·33 lines (21 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
"""Скрипт для подмены даты изменения скриншота."""
import os
import re
import subprocess
DATETIME_PATTERN = re.compile(r'.*?(\d{4}).(\d{2}).(\d{2}).(\d{2}).(\d{2}).(\d{2})\.png$')
def get_date_time(filename):
"""Получение компонент даты по регулярному выражению."""
match = DATETIME_PATTERN.search(filename)
return match[1], match[2], match[3], match[4], match[5], match[6]
def main():
"""Получение скриншотов из текущей директории, подмена даты модификации."""
for filename in os.listdir():
if filename.endswith('.png'):
year, month, day, hour, minute, second = get_date_time(filename)
cmd = f'touch -t {year}{month}{day}{hour}{minute}.{second}'
subprocess_parts = cmd.split()
subprocess_parts.append(filename)
subprocess.Popen(subprocess_parts, stdout=subprocess.PIPE).communicate()
if __name__ == '__main__':
main()