-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcli.py
107 lines (88 loc) · 2.4 KB
/
cli.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import argparse
from leetcode_study_tool.creator import ProblemsCreator
from leetcode_study_tool.presets import PRESET_MAP
def generate_parser() -> argparse.ArgumentParser:
"""
Parse the command line arguments.
Returns
-------
argparse.Namespace
The parsed command line arguments.
"""
parser = argparse.ArgumentParser(
description=("Generates problems from LeetCode questions in a desired format."),
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
input = parser.add_mutually_exclusive_group(required=True)
input.add_argument(
"--url",
"-u",
type=str,
help=(
"The URL(s) or slug(s) of the LeetCode question(s) to generate"
" problem(s) for."
),
)
input.add_argument(
"--file",
"-f",
type=str,
help=(
"The file containing the URL(s) or slug(s) of the LeetCode"
" question(s) to generate problem(s) for."
),
)
input.add_argument(
"--preset",
"-p",
type=str,
choices=PRESET_MAP.keys(),
help=("The preset to use to generate problem(s) for."),
)
parser.add_argument(
"--format",
"-F",
type=str,
default="anki",
choices=["anki", "excel"],
help="The format to save the Leetcode problem(s) in.",
)
parser.add_argument(
"--template",
"-t",
type=str,
help="Path to a custom Jinja template file for rendering problems.",
)
parser.add_argument(
"--csrf",
"-c",
type=str,
help="The CSRF token to use for LeetCode authentication.",
)
parser.add_argument(
"--output",
"-o",
type=str,
default="output.txt",
help="The output file to write the problem(s) to.",
)
parser.add_argument(
"--language",
"-l",
type=str,
help="The language to generate problem(s) for.",
default="python",
)
parser.add_argument(
"--include-code",
"-ic",
action="store_true",
help="Include solution code from NeetCode GitHub repository using the specified language.",
)
return parser
def main():
parser = generate_parser()
creator = ProblemsCreator(parser.parse_args())
creator.create_problems()
if __name__ == "__main__":
main()