-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAAA5.1.py
More file actions
68 lines (53 loc) · 1.46 KB
/
AAA5.1.py
File metadata and controls
68 lines (53 loc) · 1.46 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
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
65
def getdate(infn):
"""
Extracts the date from the file name depending on the source.
"""
name, ext = infn.split('.')
match infn[:3]:
case 'PXL':
fp = name.split('_')[1]
y = fp[:4]
m = fp[4:6]
d = fp[6:8]
case 'DCI':
fp = name.split('-')
y = fp[1]
m = fp[2]
d = fp[3]
case _:
fp = name
y = fp[:4]
m = fp[4:6]
d = fp[6:8]
return '_'.join([y, m, d])
def stat(calendar, lines):
"""
Counts the number of photos for each day.
"""
event_counts = {}
for fname in lines:
date = getdate(fname)
event_counts[calendar[date]][1] = event_counts.setdefault(calendar[date], [date, 0])[1] + 1
return event_counts
def eventselector(events):
"""
Creates a dictionary of events by dates.
"""
calendar = {}
for event in events:
parts = event.split()
date = '_'.join(parts[1:])
calendar[date] = parts[0]
return calendar
def main():
from sys import stdin
lines = [line.rstrip('\n') for line in stdin]
calendar = eventselector(lines[0:3])
event_stats = stat(calendar, lines[3:])
sorted_events = sorted(event_stats.keys())
for event in sorted_events:
date, count = event_stats[event]
for i in range(count):
print(f'{event}_{date}_{i}.jpg')
if __name__ == '__main__':
main()