-
Notifications
You must be signed in to change notification settings - Fork 0
/
runcron.py
61 lines (47 loc) · 1.51 KB
/
runcron.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
import argparse
import time
from watcher.config import get_config
from watcher.constants import (
DEFAULT_DOWNLOADS_FOLDER,
ERROR_MESSAGES,
MAX_RETRIES,
RETRY_SLEEP_SECONDS,
)
from watcher.downloader import Downloader
from watcher.email_clients.outlook import OutlookClient
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"-a", "--all", action="store_true", help="download all surveillance videos"
)
parser.add_argument(
"-f",
"--folder",
action="store",
help="specify a downloads folder",
default=DEFAULT_DOWNLOADS_FOLDER,
)
args = parser.parse_args()
return args
# TODO: Refactor code in main to watcher/*
def main():
args = parse_args()
downloader = Downloader(
username=get_config()["BLINK_USERNAME"],
password=get_config()["BLINK_PASSWORD"],
downloads_folder=args.folder,
)
auth_2fa_retries = 0
# TODO: Add other email clients and switch with argparse.
oc = OutlookClient.instance()
while downloader.blink.auth.check_key_required() and auth_2fa_retries <= MAX_RETRIES:
downloader.verify_two_factor_key(oc.get_latest_blink_2fa())
time.sleep(RETRY_SLEEP_SECONDS)
if auth_2fa_retries > MAX_RETRIES and downloader.blink.auth.check_key_required():
raise Exception(ERROR_MESSAGES.RETRY_LIMIT_REACHED)
if args.all:
downloader.download_all()
else:
downloader.download_today()
if __name__ == "__main__":
main()