makhalaf / safaribooks

Download and generate EPUB of your favorite books from O'Reilly Learning (aka Safari Books Online) library.
Do What The F*ck You Want To Public License
0 stars 0 forks source link

sweep:check if book exist skip book download #6

Open makhalaf opened 1 year ago

makhalaf commented 1 year ago

check if book exist skip book download

sweep-ai[bot] commented 1 year ago

Here's the PR! https://github.com/makhalaf/safaribooks/pull/7.

⚡ Sweep Free Trial: I used GPT-3.5 to create this ticket. You have 0 GPT-4 tickets left for the month and 2 for the day. For more GPT-4 tickets, visit our payment portal.To get Sweep to recreate this ticket, leave a comment prefixed with "sweep:" or edit the issue.


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/makhalaf/safaribooks/blob/48ae9944c89bf1911f392b2721270bc54098821f/safaribooks.py#L642-L910 https://github.com/makhalaf/safaribooks/blob/48ae9944c89bf1911f392b2721270bc54098821f/safaribooks.py#L321-L448

Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
safaribooks.py - In the _start_multiprocessing method, after line 82, add the following code:
```python
if os.path.isfile(os.path.join(self.BOOK_PATH, self.book_id + ".epub")):
self.display.log("Book already exists: %s" % self.book_id)
return
```

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Add check to skip book download if book already exists sweep/check-book-existence

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

  • Added a check to see if the EPUB file already exists in the specified output directory.
  • If the file exists, the download process is skipped and a log message is displayed.
  • This check is implemented in the _start_multiprocessing method in safaribooks.py.

Step 4: ⌨️ Coding

File Instructions Progress
safaribooks.py - In the _start_multiprocessing method, after line 82, add the following code:
python<br/> if os.path.isfile(os.path.join(self.BOOK_PATH, self.book_id + ".epub")):<br/> self.display.log("Book already exists: %s" % self.book_id)<br/> return<br/> | ✅ Commit 3872391
I have finished coding the issue. I am now reviewing it for completeness.

Step 5: 🔁 Code Review

Here are the my self-reviews of my changes at sweep/check-book-existence.

Here is the 1st review

No changes required. The code changes in safaribooks.py on lines 1121-1122 are correct and do not contain any errors.

I finished incorporating these changes.


To recreate the pull request, leave a comment prefixed with "sweep:" or edit the issue. Join Our Discord