forked from marcboeker/gmail-to-sqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (43 loc) · 1.36 KB
/
main.py
File metadata and controls
55 lines (43 loc) · 1.36 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
import argparse
import os
import sys
import auth
import db
import sync
def prepare_data_dir(data_dir: str) -> None:
"""
Get the project name from command line arguments and create a directory for it if it doesn't exist.
Raises:
ValueError: If project name is not provided.
Returns:
None
"""
if not os.path.exists(data_dir):
os.makedirs(data_dir)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("command", help="The command to run: {sync, sync-message}")
parser.add_argument(
"--data-dir", help="The path where the data should be stored", required=True
)
parser.add_argument(
"--full-sync",
help="Force a full sync of all messages",
action="store_true",
)
parser.add_argument(
"--message-id",
help="The ID of the message to sync",
)
args = parser.parse_args()
prepare_data_dir(args.data_dir)
credentials = auth.get_credentials(args.data_dir)
db_conn = db.init(args.data_dir)
if args.command == "sync":
sync.all_messages(credentials, full_sync=args.full_sync)
elif args.command == "sync-message":
if args.message_id is None:
print("Please provide a message ID")
sys.exit(1)
sync.single_message(credentials, args.message_id)
db_conn.close()