-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path1se-files-calendar-mtime
executable file
·64 lines (44 loc) · 1.38 KB
/
1se-files-calendar-mtime
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
"""
usage: 1se-files-calendar-mtime FILE...
Print a calendar listing of every day in the year, showing which days have
a file modified on that day.
The purpose of this is to organize things like a 1SE spreadsheet to show which
days have coverage in video files from a directory.
For example:
1se-files-calendar-mtime *.mp4
"""
import json
import os
import sys
from datetime import date, timedelta
def main(files: list[str]) -> None:
years: set[int] = set()
dates_dict: dict[date, list] = {}
for f in files:
stat = os.stat(f)
day = date.fromtimestamp(stat.st_mtime)
if day not in dates_dict:
dates_dict[day] = []
dates_dict[day].append(f)
years.add(day.year)
for year in sorted(years):
day = date(year, 1, 1)
while day.year == year:
month = day.strftime("%B")
dom = day.strftime("%e").strip()
fields = [
str(day.year),
month + " " + dom,
]
if day in dates_dict:
fields += ["TRUE", json.dumps(sorted(dates_dict[day]))]
else:
fields += ["", ""]
print("\t".join(fields))
day = day + timedelta(days=1)
if __name__ == "__main__":
if len(sys.argv) < 2:
print(__doc__.strip())
sys.exit(1)
main(sys.argv[1:])