-
Notifications
You must be signed in to change notification settings - Fork 9
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
Conversation
There was a problem hiding this 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 .
leetcode_export/__main__.py
Outdated
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() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
options: | ||
optional arguments: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 saysoptions
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
.
There was a problem hiding this comment.
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
@NeverMendel Hi, I updated the code. Please let me know if there are some problems. Updates:
|
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). |
Thank you! I've just released the new version! |
--no-problem-statement-files: do not save problem statement files
--only-latest-submission: save the latest solution code with the corresponding extension