@@ -30,6 +30,12 @@ def parse_args():
30
30
default = "${question_id}-${title_slug}" ,
31
31
help = "problem folder name format" ,
32
32
)
33
+ parser .add_argument (
34
+ "--no-problem-statement" ,
35
+ dest = "no_problem_statement" ,
36
+ action = "store_true" ,
37
+ help = "do not save problem statement" ,
38
+ )
33
39
parser .add_argument (
34
40
"--problem-statement-filename" ,
35
41
type = str ,
@@ -55,6 +61,12 @@ def parse_args():
55
61
action = "store_true" ,
56
62
help = "save accepted submissions only" ,
57
63
)
64
+ parser .add_argument (
65
+ "--only-last-submission" ,
66
+ dest = "only_last_submission" ,
67
+ action = "store_true" ,
68
+ help = "only save the last submission for each programming language" ,
69
+ )
58
70
parser .add_argument (
59
71
"--language" ,
60
72
dest = "language_unprocessed" ,
@@ -145,14 +157,41 @@ def main():
145
157
os .chdir (args .folder )
146
158
147
159
title_slug_to_problem_folder_name : dict [str , str ] = dict ()
160
+ title_slug_to_exported_languages : dict [str , set [str ]] = dict ()
161
+
162
+ last_submission_timestamp : Optional [int ] = None
148
163
149
164
for submission in leetcode .get_submissions ():
165
+ if (
166
+ last_submission_timestamp is not None
167
+ and submission .timestamp > last_submission_timestamp
168
+ ):
169
+ logging .warning (
170
+ "Submissions are not in reverse chronological order, --only-last-submission flag might not work as expected if used. Please report this issue on GitHub attaching the debug.log file: https://github.com/NeverMendel/leetcode-export/issues"
171
+ )
172
+ last_submission_timestamp = submission .timestamp
173
+
150
174
if args .only_accepted and submission .status_display != "Accepted" :
151
175
continue
152
176
153
177
if args .language and submission .lang not in args .language :
154
178
continue
155
179
180
+ if submission .title_slug not in title_slug_to_exported_languages :
181
+ title_slug_to_exported_languages [submission .title_slug ] = set ()
182
+
183
+ if (
184
+ args .only_last_submission
185
+ and submission .title_slug in title_slug_to_exported_languages
186
+ and submission .lang
187
+ in title_slug_to_exported_languages [submission .title_slug ]
188
+ ):
189
+ logging .info (
190
+ f"The latest submission for { submission .title_slug } in { submission .lang } has already been exported, skipping this submission"
191
+ )
192
+ continue
193
+ title_slug_to_exported_languages [submission .title_slug ].add (submission .lang )
194
+
156
195
if submission .title_slug not in title_slug_to_problem_folder_name :
157
196
problem_statement = leetcode .get_problem_statement (submission .title_slug )
158
197
problem_folder_name = problem_folder_name_template .substitute (
@@ -168,7 +207,9 @@ def main():
168
207
problem_statement_filename = problem_statement_filename_template .substitute (
169
208
** problem_statement .__dict__
170
209
)
171
- if not os .path .exists (problem_statement_filename ):
210
+ if not args .no_problem_statement and not os .path .exists (
211
+ problem_statement_filename
212
+ ):
172
213
with open (problem_statement_filename , "w+" ) as problem_statement_file :
173
214
problem_statement_file .write (
174
215
problem_statement_template .substitute (
0 commit comments