Skip to content

Commit

Permalink
1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
vardecab committed Mar 18, 2021
1 parent d3120a6 commit 79fe91b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,25 @@
> Do something useful with your Kindle notes :) This script extracts individual words from `My Clippings` file hidden on your Kindle e-reader, translates them using Google Translate and exports the pair "original word" → "translation" into a `.txt` file from which you can learn these words or import them into an application such as [Quizlet](https://quizlet.com/).
## Screenshots
![](https://user-images.githubusercontent.com/6877391/111391325-ac6d1f80-86b4-11eb-9816-470e442a1034.png)
![](https://user-images.githubusercontent.com/6877391/111392214-631dcf80-86b6-11eb-99c1-95ba4c997834.png)
![output](https://user-images.githubusercontent.com/6877391/111391325-ac6d1f80-86b4-11eb-9816-470e442a1034.png)
![macOS notification](https://user-images.githubusercontent.com/6877391/111626634-8e0b3f00-87ee-11eb-8b1c-0379db96bc8c.jpeg)
![sets in Quizlet](https://user-images.githubusercontent.com/6877391/111392214-631dcf80-86b6-11eb-99c1-95ba4c997834.png)

## How to use

### Speed things up ⚡
`deep-translator` works very slowly with Google Translate so we need to do a little tweak first. Install the package and go to the location where `deep-translator` is installed:
```sh
pip install deep-translator
pip show deep-translator
```
Open `google_trans.py` & go to line 177. Edit:
```py
# sleep(2) # => 33.33 mins to translate 1000 words
sleep(0.1) # => 1.66 mins to translate 1000 words
```
Save.

### Windows
1. Connect your Kindle via USB cable to your computer.
2. Download `script.zip` from [Releases](https://github.com/vardecab/kindle-words/releases).
Expand All @@ -25,6 +40,7 @@
```py
pip install inputimeout
pip install deep_translator
pip install pync
```
3. Navigate to the folder you cloned/downloaded & run the script:
```sh
Expand All @@ -50,6 +66,7 @@ python script.py

## Release History

- 1.1.4: Added notifications for macOS & Windows.
- 1.1.3: Added support for macOS.
- 1.1.2: Added `try/except` to fix a `FileNotFoundError` error.
- 1.1.1: Fixed `io.open` bug; added some `try/except` to catch more errors; re-enabled `timeout_time`; added `last_word` export so it's easy to see which words are new and which are old. Published in [Releases](https://github.com/vardecab/kindle-words/releases).
Expand Down Expand Up @@ -85,6 +102,8 @@ GNU General Public License v3.0, see [LICENSE.md](https://github.com/vardecab/um
### Packages
- [deep-translator](https://github.com/nidhaloff/deep-translator)
- [inputimeout](https://pypi.org/project/inputimeout/)
- [win10toast-click](https://github.com/vardecab/win10toast-click)
- [pync](https://github.com/SeTeM/pync)
### Articles
- [Text Translation with Google Translate API in Python](https://stackabuse.com/text-translation-with-google-translate-api-in-python/)
- [Change python 3.7 default encoding from cp1252 to cp65001 aka UTF-8](https://stackoverflow.com/questions/56995919/change-python-3-7-default-encoding-from-cp1252-to-cp65001-aka-utf-8)
Expand All @@ -93,4 +112,6 @@ GNU General Public License v3.0, see [LICENSE.md](https://github.com/vardecab/um
- [Python switch case](https://www.journaldev.com/15642/python-switch-case)
- [Using .write function with multiple arguments for writing to a txt file - Python](https://stackoverflow.com/questions/47425891/using-write-function-with-multiple-arguments-for-writing-to-a-txt-file-python)
### Tools
- [regex101](https://regex101.com/)
- [regex101](https://regex101.com/)
### Other
- [Flaticon / Freepik](https://www.flaticon.com/)
Binary file added icons/translation.ico
Binary file not shown.
24 changes: 22 additions & 2 deletions script.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding = 'utf-8')

### notifications
# imports
from sys import platform # check platform (Windows/macOS)
if platform == "darwin":
import pync
elif platform == 'win32':
import win10toast_click

### path to file: https://www.journaldev.com/15642/python-switch-case
from sys import platform # check platform (Windows/Linux/macOS)
if platform == 'win32':
path = {
'C' : r'C:\documents\My Clippings.txt',
Expand All @@ -27,6 +34,7 @@
from inputimeout import inputimeout, TimeoutOccurred # input timeout: https://pypi.org/project/inputimeout/
# timeout_time = 0 # *NOTE: test
timeout_time = 5 # *NOTE: prod
print(f'Script will wait {timeout_time} seconds for the input and then will continue with a default value.')

# select source language
try:
Expand Down Expand Up @@ -172,6 +180,12 @@
counter += 1
print('Words are translated & final file is exported!')

### notifications
if platform == "darwin":
pync.notify(f'Translated {len(to_translate)} words.', title='kindle-words', contentImage="https://i.postimg.cc/3R0tLQ3H/translation.png", sound="Funk") # appIcon="" doesn't work, using contentImage instead
elif platform == "win32":
toaster.show_toast(msg=f'Translated {len(to_translate)} words.', title="kindle-words", icon_path="./icons/translation.ico", duration=None, threaded=True) # duration=None - leave notification in Notification Center; threaded=True - rest of the script will be allowed to be executed while the notification is still active

### export list for future comparison
with open('data/saved_location', 'wb') as file_export:
pickle.dump(single_words, file_export)
Expand All @@ -181,7 +195,13 @@
run_time = round(end_time-start_time,2)
print(len(to_translate), 'words were translated in:', run_time, "seconds (" + str(round(run_time/60,2)), "minutes).")

else:
else:
### notifications
if platform == "darwin":
pync.notify(f'Nothing new to translate.', title='kindle-words', contentImage="https://i.postimg.cc/3R0tLQ3H/translation.png", sound="Funk") # appIcon="" doesn't work, using contentImage instead
elif platform == "win32":
toaster.show_toast(msg=f'Nothing new to translate.', title="kindle-words", icon_path="./icons/translation.ico", duration=None, threaded=True) # duration=None - leave notification in Notification Center; threaded=True - rest of the script will be allowed to be executed while the notification is still active

print('Nothing new to translate. Exiting...')

### runtime
Expand Down

0 comments on commit 79fe91b

Please sign in to comment.