Skip to content

Add --no-problem-statement and --only-last-submission flags #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 13, 2023

Conversation

GoingMyWay
Copy link
Contributor

--no-problem-statement-files: do not save problem statement files
--only-latest-submission: save the latest solution code with the corresponding extension

Copy link
Owner

@NeverMendel NeverMendel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @GoingMyWay,

Thank you for adding new features to leetcode-export!

I've added a couple of suggestions, let me know what you think.

Also can you please format the code with black, running the following will do it:

pip install black
black .

Comment on lines 169 to 176
if submission.title_slug in title_slug_to_extension and \
submission.extension in title_slug_to_extension[submission.title_slug] and \
args.only_latest_submission:
logging.info(f"Saving only the latest submission of the question {submission.title_slug} with "
f"{submission.extension} extension, skipping it")
continue
else:
title_slug_to_extension[submission.title_slug] = set()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good but it's missing an edge case, refactoring the code a bit will fix it.

Consider the following sequence of submission programming languages: cpp, java, cpp, cpp.

This code will download "cpp, java, cpp" because in the second iteration (java) the condition will resolve to false and title_slug_to_extension[submission.title_slug] will be substituted with a new empty set

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm not sure if we should rely on the API returning the submissions in reverse chronological order. As it's LeetCode private API we don't have any guarantee on it, they could change its behaviour anytime

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good but it's missing an edge case, refactoring the code a bit will fix it.

Consider the following sequence of submission programming languages: cpp, java, cpp, cpp.

This code will download "cpp, java, cpp" because in the second iteration (java) the condition will resolve to false and title_slug_to_extension[submission.title_slug] will be substituted with a new empty set

Thanks for pointing out. I have fixed it and will push it soon.

Copy link
Contributor Author

@GoingMyWay GoingMyWay Feb 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I'm not sure if we should rely on the API returning the submissions in reverse chronological order. As it's LeetCode private API we don't have any guarantee on it, they could change its behaviour anytime

It could be a problem. To solve it, in the newly committed code, I got all submissions and sorted them by the date_formatted.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the follow up!

After further consideration, I think it's best to write the submission as soon as possible otherwise users might think that the script doesn't work if it takes 5-10 minutes before a submission appears in the output folder.

Note: the script might take several minutes to execute because of LeetCode API rate limits

Sorry for the confusion, I made the required changes and added a warning message prompting users to create a GitHub issue if the script detects that submissions are not in reverse chronological order.

README.md Outdated
Comment on lines 119 to 120
options:
optional arguments:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the help message that is displayed when the script is run with the -h flag (ex. leetcode-export -h). When I run it, the help message says options for me, is it the same for you?
If so, I would keep this text the same as the script help message

Copy link
Contributor Author

@GoingMyWay GoingMyWay Feb 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the help message that is displayed when the script is run with the -h flag (ex. leetcode-export -h). When I run it, the help message says options for me, is it the same for you? If so, I would keep this text the same as the script help message

In Python 3.7, 3.8 and 3.9, it shows optional arguments.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing that out!

It looks like they've changed it to optional in Python 3.10. I would keep options because it's what will be used from now on.

For reference:
Python 3.9: https://github.com/python/cpython/blob/3.9/Lib/argparse.py#L1729
Python 3.10: https://github.com/python/cpython/blob/3.10/Lib/argparse.py#L1730

@GoingMyWay
Copy link
Contributor Author

GoingMyWay commented Feb 10, 2023

@NeverMendel Hi, I updated the code. Please let me know if there are some problems.

Updates:

  1. Fixed the corner case raised in Add --no-problem-statement and --only-last-submission flags #2 (comment)
  2. Save all submissions first and then sort the submission by the date_formatted.
  3. Use --no-problem-statements.
  4. Update the README.md

@NeverMendel NeverMendel changed the title add --no-problem-statement-files and --only-latest-submission Add --no-problem-statement and --only-last-submission flags Feb 13, 2023
@NeverMendel
Copy link
Owner

Thank you for the follow-up @GoingMyWay!

I made some small changes and I will merge the pull request.

I will release this new feature tomorrow in leetcode-export version 2.1.0

@NeverMendel NeverMendel merged commit 678c78f into NeverMendel:main Feb 13, 2023
@GoingMyWay
Copy link
Contributor Author

Thank you for the follow-up @GoingMyWay!

I made some small changes and I will merge the pull request.

I will release this new feature tomorrow in leetcode-export version 2.1.0

Thanks. Your commits are great. I used this repo to export my LeetCode submissions (https://github.com/GoingMyWay/LeetCode).

@NeverMendel
Copy link
Owner

Thank you! I've just released the new version!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants