-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add check to skip book download if book already exists #7
base: master
Are you sure you want to change the base?
Conversation
@CodiumAI-Agent /review |
PR Analysis
PR Feedback
How to use
|
@CodiumAI-Agent //improve |
SafariBooks(args_parsed) | ||
# Hint: do you want to download more then one book once, initialized more than one instance of `SafariBooks`... | ||
sys.exit(0) | ||
sys.exit(0) |
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.
Suggestion: Avoid using sys.exit(0) directly in the code. It's better to return from the function or raise an exception that can be caught at a higher level. This will make the code more maintainable and easier to test.
SafariBooks(args_parsed) | |
# Hint: do you want to download more then one book once, initialized more than one instance of `SafariBooks`... | |
sys.exit(0) | |
sys.exit(0) | |
SafariBooks(args_parsed) | |
# Hint: do you want to download more then one book once, initialized more than one instance of `SafariBooks`... | |
return |
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.
Done.
Hi @makhalaf, I decided to make the following changes:
|
Hi @CodiumAI-Agent, I decided to make the following changes:
|
PR Analysis
PR Feedback
How to use
|
Hi @makhalaf, I decided to make the following changes:
|
safaribooks.py
Outdated
try: | ||
if len(full_queue) > 5: | ||
for i in range(0, len(full_queue), 5): | ||
self._start_multiprocessing(operation, full_queue[i:i + 5]) |
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.
Suggestion: The recursive call to _start_multiprocessing within the same function can lead to a stack overflow if the queue size is large. Consider using a while loop instead.
try: | |
if len(full_queue) > 5: | |
for i in range(0, len(full_queue), 5): | |
self._start_multiprocessing(operation, full_queue[i:i + 5]) | |
def _start_multiprocessing(self, operation, full_queue): | |
try: | |
while len(full_queue) > 5: | |
chunk = full_queue[:5] | |
full_queue = full_queue[5:] | |
process_queue = [Process(target=operation, args=(arg,)) for arg in chunk] | |
for proc in process_queue: | |
proc.start() | |
for proc in process_queue: | |
proc.join() |
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.
Done.
safaribooks.py
Outdated
@@ -1121,4 +1124,4 @@ def create_epub(self): | |||
|
|||
SafariBooks(args_parsed) | |||
# Hint: do you want to download more then one book once, initialized more than one instance of `SafariBooks`... | |||
sys.exit(0) | |||
return |
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.
Suggestion: The 'return' statement at the end of the script is not necessary. Python scripts end naturally when they run out of code to execute.
return | |
SafariBooks(args_parsed) | |
# Hint: do you want to download more then one book once, initialized more than one instance of `SafariBooks`... |
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.
No changes made. Please add more details so I know what to change.
safaribooks.py
Outdated
try: | ||
if len(full_queue) > 5: | ||
for i in range(0, len(full_queue), 5): | ||
self._start_multiprocessing(operation, full_queue[i:i + 5]) | ||
|
||
else: | ||
process_queue = [Process(target=operation, args=(arg,)) for arg in full_queue] | ||
for proc in process_queue: | ||
proc.start() | ||
|
||
for proc in process_queue: | ||
proc.join() | ||
except IOError as e: | ||
self.display.error(f"IOError occurred: {e}") |
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.
Suggestion: The IOError exception handling is too broad and may hide other issues. Consider specifying the exact error you're expecting, or add more specific error handling.
try: | |
if len(full_queue) > 5: | |
for i in range(0, len(full_queue), 5): | |
self._start_multiprocessing(operation, full_queue[i:i + 5]) | |
else: | |
process_queue = [Process(target=operation, args=(arg,)) for arg in full_queue] | |
for proc in process_queue: | |
proc.start() | |
for proc in process_queue: | |
proc.join() | |
except IOError as e: | |
self.display.error(f"IOError occurred: {e}") | |
try: | |
... | |
except IOError as e: | |
if e.errno == errno.ENOENT: | |
self.display.error(f"File not found error occurred: {e}") | |
else: | |
raise e |
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.
No changes made. Please add more details so I know what to change.
Hi @CodiumAI-Agent, I decided to make the following changes:
|
Description
This PR adds a check to skip the book download process if the book already exists in the specified output directory. This helps to avoid unnecessary downloads and saves resources.
Summary
_start_multiprocessing
method insafaribooks.py
.Fixes #6.
To checkout this PR branch, run the following command in your terminal:
To get Sweep to edit this pull request, leave a comment below or in the code. Leaving a comment in the code will only modify the file but commenting below can change the entire PR.