@@ -30,6 +30,12 @@ def parse_args():
3030 default = "${question_id}-${title_slug}" ,
3131 help = "problem folder name format" ,
3232 )
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+ )
3339 parser .add_argument (
3440 "--problem-statement-filename" ,
3541 type = str ,
@@ -55,6 +61,12 @@ def parse_args():
5561 action = "store_true" ,
5662 help = "save accepted submissions only" ,
5763 )
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+ )
5870 parser .add_argument (
5971 "--language" ,
6072 dest = "language_unprocessed" ,
@@ -145,14 +157,41 @@ def main():
145157 os .chdir (args .folder )
146158
147159 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
148163
149164 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+
150174 if args .only_accepted and submission .status_display != "Accepted" :
151175 continue
152176
153177 if args .language and submission .lang not in args .language :
154178 continue
155179
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+
156195 if submission .title_slug not in title_slug_to_problem_folder_name :
157196 problem_statement = leetcode .get_problem_statement (submission .title_slug )
158197 problem_folder_name = problem_folder_name_template .substitute (
@@ -168,7 +207,9 @@ def main():
168207 problem_statement_filename = problem_statement_filename_template .substitute (
169208 ** problem_statement .__dict__
170209 )
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+ ):
172213 with open (problem_statement_filename , "w+" ) as problem_statement_file :
173214 problem_statement_file .write (
174215 problem_statement_template .substitute (
0 commit comments