forked from cyborgsphinx/ios-inlets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find-duplicates.py
51 lines (46 loc) · 1.74 KB
/
find-duplicates.py
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
import fnmatch
import logging
import os
import ios_shell.shell as ios
def main():
ids = {}
shell_exts = ["bot", "che", "ctd", "ubc", "med", "xbt", "adcp", "cur"]
to_exclude = ["HISTORY", "old", "Archive", "Bottle", "BOTTLE", "ALTERNATE_VERSION"]
print(
"Files included in",
", ".join(to_exclude),
"subdirectories were not compared for duplicates",
)
# make a list of all elements in shell_exts followed by their str.upper() versions
exts = [
item
for sublist in [[ext, ext.upper()] for ext in shell_exts]
for item in sublist
]
for root, dirs, files in os.walk("data"):
for ext in exts:
for item in fnmatch.filter(files, f"*.{ext}"):
file_name = os.path.join(root, item)
try:
shell = ios.ShellFile.fromfile(file_name, process_data=False)
except Exception:
logging.exception(f"Error reading {file_name}")
continue
id = (
shell.file.start_time.strftime("%Y/%m/%dT%H:%M:%S")
+ shell.file.end_time.strftime("%Y/%m/%dT%H:%M:%S")
+ str(shell.file.number_of_records)
+ str(shell.file.number_of_channels)
+ shell.administration.mission
+ shell.location.station
+ str(shell.location.event_number)
+ ext
)
if id in ids:
print(file_name, "may be a duplicate of", ids[id])
ids[id] = file_name
for exclude in to_exclude:
if exclude in dirs:
dirs.remove(exclude)
if __name__ == "__main__":
main()