@@ -17,6 +17,8 @@ def __init__(self):
17
17
# Instance specific variables
18
18
self .browserFlag = False
19
19
self .fileFlag = False
20
+ self .randomFlag = False
21
+ self .contentFlag = False
20
22
21
23
self ._question_id : int = None
22
24
self ._title_slug : str = None
@@ -107,8 +109,7 @@ def _execute(self, args):
107
109
question_content = QuestionContent (problem .titleSlug )
108
110
console .print (question_info_table )
109
111
console .print (question_content )
110
-
111
- else :
112
+ elif getattr (args , 'id' ) != 0 :
112
113
try :
113
114
with Loader ('Fetching problem info...' , '' ):
114
115
self .data = self .leet_api .get_request (self .API_URL )
@@ -124,6 +125,8 @@ def _execute(self, args):
124
125
console .print (f"{ e .__class__ .__name__ } : { e } " , style = ALERT )
125
126
if self .fileFlag :
126
127
self .create_submission_file (self .title_slug )
128
+ else :
129
+ console .print ("Invalid ID has been provided. Please try again." , style = ALERT )
127
130
128
131
@classmethod
129
132
def create_submission_file (cls , title_slug : str = None ) -> None :
@@ -133,9 +136,11 @@ def create_submission_file(cls, title_slug: str = None) -> None:
133
136
Args:
134
137
title_slug (str): The title slug of the problem.
135
138
"""
139
+ watermark_info = '# This file was created by pyleetcode-cli software.\n # Do NOT modify the name of the file.\n \n '
136
140
question = GetQuestionDetail (title_slug )
137
141
file_name = f"{ question .question_id } .{ question .title_slug } .py"
138
142
with open (file_name , 'w' ) as file :
143
+ file .write (watermark_info )
139
144
file .write (question .code_snippet )
140
145
console .print (f"File '{ file_name } ' has been created." )
141
146
@@ -146,12 +151,15 @@ def show(self):
146
151
link = self .config .host + f'/problems/{ self .title_slug } /'
147
152
console .print (f'Link to the problem: { link } ' )
148
153
self .open_in_browser (link )
149
- else :
154
+ elif self . contentFlag :
150
155
question_info_table = QuestionInfoTable (self .title_slug )
151
156
console .print (question_info_table )
152
157
question_content = QuestionContent (self .title_slug )
153
158
console .print (question_content )
154
-
159
+ else :
160
+ question_info_table = QuestionInfoTable (self .title_slug )
161
+ console .print (question_info_table )
162
+
155
163
def __parse_args (self , args ) -> None :
156
164
""" Parses the arguments passed to the query.
157
165
@@ -161,6 +169,10 @@ def __parse_args(self, args) -> None:
161
169
self .browserFlag = True
162
170
if getattr (args , 'file' ):
163
171
self .fileFlag = True
172
+ if getattr (args , 'random' ):
173
+ self .randomFlag = True
174
+ if getattr (args , 'contents' ):
175
+ self .contentFlag = True
164
176
165
177
@property
166
178
def data (self ):
0 commit comments