-
Notifications
You must be signed in to change notification settings - Fork 4
/
organize.py
executable file
·61 lines (51 loc) · 2.01 KB
/
organize.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
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
"""
Tool for organizing and cleaning up Google takeout data.
"""
import argparse
import distutils.core
import os
def dir_path(string):
"""Determines if the argument is an existing directory."""
if os.path.isdir(string):
return string
else:
raise argparse.ArgumentTypeError(
'Path "' + string + '" is not a directory.')
PARSER = argparse.ArgumentParser(description=('Tool for processing and '
'organizing Google takeout '
'data.'))
PARSER.add_argument('--photos_dir', type=dir_path,
help='The directory containing Google Photos takeout '
'archives (i.e. one or multiple zip file)')
PARSER.add_argument('--mbox_file',
help='The mbox file with Gmail takeout data.')
def _maybe_organize_photos_takeout(takeout_dir):
if not takeout_dir:
print('Invalid (or no) Photos takeout archive directory specified. Not '
'extracting photos from archives.')
return
else:
organize_photos = input('Organize Photos takeout archives? y/n: ')
organize_photos = distutils.util.strtobool(organize_photos)
if not organize_photos:
return
import photos
photos.organize_photos_takeout(takeout_dir)
def _maybe_extract_email_attachments(mbox_file_path):
if (mbox_file_path and os.path.isfile(mbox_file_path) and
mbox_file_path.endswith('.mbox')):
answer = input('Extract mailbox attachments? y/n: ')
answer = distutils.util.strtobool(answer)
if answer:
import mail
mail.extract_mail_attachments(mbox_file_path)
else:
print('Invalid (or no) .mbox path specified. Not extracting email '
'attachments.')
def main():
args = PARSER.parse_args()
_maybe_organize_photos_takeout(args.photos_dir)
_maybe_extract_email_attachments(args.mbox_file)
if __name__ == '__main__':
main()