Skip to content

Commit

Permalink
1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
vardecab committed Mar 18, 2021
1 parent 6cc1552 commit d3120a6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 23 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,36 @@

## How to use
### Windows

1. Connect your Kindle via USB cable to your computer.
2. Download `script.zip` from [Releases](https://github.com/vardecab/kindle-words/releases).
3. Run `script.exe`.
3. Go to the download location, unzip & run `script.exe`.
4. Write source & target languages or wait if defaults (`en` & `pl`) are ok.
5. Write drive letter associated with Kindle or wait if default (`D`) is ok.
6. Wait a few minutes - words are being translated.
7. Go to `script\output\kindle-words_export.txt` to check exported file.
8. (optional) Add it to [Quizlet](https://quizlet.com/).
9. Voilà ✨

### macOS
1. Connect your Kindle via USB cable to your Mac.
2. Clone or download this repo.
3. Open Terminal/iTerm and install necessary packages (use `pip` or `pip3`):
```py
pip install inputimeout
pip install deep_translator
```
3. Navigate to the folder you cloned/downloaded & run the script:
```sh
cd '/Users/USER/Downloads/kindle-words'
python script.py
```
4. Write source & target languages or wait if defaults (`en` & `pl`) are ok.
5. Write your Kindle's name or wait if default (`Kindle`) is ok.
6. Wait a few minutes - words are being translated.
7. Go to `output/kindle-words_export.txt` to check exported file.
8. (optional) Add it to [Quizlet](https://quizlet.com/).
9. Voilà ✨

## Roadmap

- 🎯 Dictionary definitions. (Need a different API)
Expand All @@ -31,6 +50,7 @@

## Release History

- 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).
- 1.1: Quite a big re-write: it now works properly with `My Clippings.txt` file from Kindle - all bugs are fixed. Initial run takes ~ 10 minutes to complete (depending on the size of your file) but afterwards it's usually < 1 minute because data from previous run is stored locally for comparison - only new words are being translated to save time and improve speed.
Expand Down
58 changes: 37 additions & 21 deletions script.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
'F' : r'F:\documents\My Clippings.txt',
'f' : r'F:\documents\My Clippings.txt'
}
# elif platform == "darwin": # macOS
# path = {} # TODO

### input timeout
from inputimeout import inputimeout, TimeoutOccurred # input timeout: https://pypi.org/project/inputimeout/
# timeout_time = 0 # *NOTE: test
timeout_time = 3 # *NOTE: prod
timeout_time = 5 # *NOTE: prod

# select source language
try:
Expand All @@ -45,27 +43,45 @@
select_target_language = 'pl'

# select Kindle drive letter
try:
kindle_drive_letter = inputimeout(prompt="Enter the drive letter that is assigned to your Kindle (C/D/E/F) (default: D): ", timeout=timeout_time)
with io.open(path.get(kindle_drive_letter,r'x:\documents\My Clippings.txt'), "r", encoding="utf-8") as source_file:
read_source_file = source_file.readlines() # read the file to [list]
except TimeoutOccurred:
# print ("Time ran out.")
# *NOTE: test
# with io.open(r'./test/test.txt', "r", encoding="utf-8") as source_file:
# print('Selecting test file...')
# read_source_file = source_file.readlines() # read the file to [list]
# *NOTE: prod
if platform == 'win32': # Windows
try:
kindle_drive_letter = inputimeout(prompt="Enter the drive letter that is assigned to your Kindle (C/D/E/F) (default: D): ", timeout=timeout_time)
with io.open(path.get(kindle_drive_letter,r'x:\documents\My Clippings.txt'), "r", encoding="utf-8") as source_file:
read_source_file = source_file.readlines() # read the file to [list]
except TimeoutOccurred:
# print ("Time ran out.")
# *NOTE: test
# with io.open(r'./test/test.txt', "r", encoding="utf-8") as source_file:
# print('Selecting test file...')
# read_source_file = source_file.readlines() # read the file to [list]
# *NOTE: prod
try:
with io.open(r'D:\documents\My Clippings.txt', "r", encoding="utf-8") as source_file:
print('Time ran out, selecting default drive (D)...')
read_source_file = source_file.readlines() # read the file to [list]
except:
print('Kindle is either not connected or has a custom drive assignment. Try again. Exiting...')
exit()
except FileNotFoundError:
print ('Looks like Kindle is not assigned to this drive letter. Try a different one next time. Exiting...')
exit()

elif platform == "darwin": # macOS
try:
with io.open(r'D:\documents\My Clippings.txt', "r", encoding="utf-8") as source_file:
print('Time ran out, selecting default drive (D)...')
kindle_name = inputimeout(prompt="Enter your Kindle's name: ", timeout=timeout_time).lower()
with io.open(f'/Volumes/{kindle_name}/documents/My Clippings.txt', "r", encoding="utf-8") as source_file:
read_source_file = source_file.readlines() # read the file to [list]
except:
print('Kindle is not connected. Connect your Kindle and try again. Exiting...')
except TimeoutOccurred:
try:
with io.open('/Volumes/Kindle/documents/My Clippings.txt', "r", encoding="utf-8") as source_file:
print('Time ran out, choosing default name (Kindle)...')
read_source_file = source_file.readlines() # read the file to [list]
except:
print('Kindle is either not connected or it has a custom name. Try again. Exiting...')
exit()
except FileNotFoundError:
print ("Looks like this name doesn't work. Try a different one next time. Exiting...")
exit()
except FileNotFoundError:
print ('Looks like Kindle is not assigned to this drive letter. Try a different one next time. Exiting...')
exit()

### create output & data folders
import os
Expand Down

0 comments on commit d3120a6

Please sign in to comment.