-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (58 loc) · 1.89 KB
/
main.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
62
63
64
65
66
67
68
69
from Uses.UseCase import UseCase
from Drivers.Chrome.Config import DriverConfig
import re
import argparse
from datetime import date, datetime
import logging
import os
def setup_logging():
log_path = "./logs_files/"
if not os.path.isdir(log_path):
os.mkdir(log_path)
logging.basicConfig(
format="[%(asctime)s] [Line %(lineno)d] [%(levelname)s] %(message)s",
filemode="w",
level=logging.INFO,
)
def parse_arguments():
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument(
"--date",
type=str,
help="Specify the date for data retrieval. Use 'Today' for current data, or input in the format: "
"[Three-letter month abbreviation]-[DD]-[YYYY] (e.g., 'Feb-10-2024').",
)
group.add_argument(
"--number_of_days",
type=int,
nargs="?",
const=-1,
help="Specify the number of days for data retrieval. "
"If you wish to retrieve all available data from all dates, "
"simply omit specifying a number.",
)
parser.add_argument(
"--headless",
action="store_true",
help="Run the program in headless mode.",
)
return parser.parse_args()
def main():
setup_logging()
args = parse_arguments()
download_files = UseCase(DriverConfig(args.headless))
if args.date:
if args.date.lower() == "today":
download_files.execute(date=date.today().strftime("%d %b %Y"))
elif re.match(r"[A-Z][a-z]{2}-\d{2}-\d{4}", args.date):
download_files.execute(
date=datetime.strptime(args.date, "%b-%d-%Y").strftime("%d %b %Y")
)
else:
logging.error("Invalid date format")
exit(1)
else:
download_files.execute(number_of_days=args.number_of_days)
if __name__ == "__main__":
main()