Skip to content

Commit

Permalink
1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
vardecab committed Mar 17, 2021
1 parent bc3b5a4 commit 267e85a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ test
output/*
!output/.gitkeep
data/*
!data/.gitkeep
!data/.gitkeep

# build
script.spec
build
dist
__pycache__
rebuild.bat
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
### Windows

1. Connect your Kindle via USB cable to your computer.
2. Download `script.py` from this repo.
2. Download `script.exe` from [Releases](https://github.com/vardecab/kindle-words/releases).
3. Run it.
4. Write source & target languages (eg. `en` & `es`).
5. Write drive letter associated with Kindle (eg. `D` for D:).
6. Wait a few minutes.
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 `output/kindle-words_export.txt` to check exported file.
8. (optional) Add it to [Quizlet](https://quizlet.com/).
9. Voilà ✨
Expand All @@ -31,6 +31,7 @@

## Release History

- 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.
- 1.0.0: Using new API - [deep-translator](https://github.com/nidhaloff/deep-translator).
- 0.12.5: Bug in the API discovered.
Expand Down
32 changes: 22 additions & 10 deletions script.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

### 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 = 0 # *NOTE: test
timeout_time = 3 # *NOTE: prod

# select source language
try:
Expand All @@ -46,20 +46,24 @@

# select Kindle drive letter
try:
kindle_drive_letter = inputimeout(prompt="Enter the drive letter that is assigned to your Kindle (C/D/E/F): ", timeout=timeout_time)
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.read()
read_source_file = source_file.readlines() # read the file to [list]
except TimeoutOccurred:
print ("Time ran out.")
# 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
with io.open(r'D:\documents\My Clippings.txt', "r", encoding="utf-8") as source_file:
print('Selecting default drive (D)...')
read_source_file = source_file.readlines() # read the file to [list]
except FileNotFoundError: # TODO: better way to handle errors
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 not connected. Connect your Kindle and 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()

Expand All @@ -70,6 +74,14 @@
if not os.path.exists('data'):
os.makedirs('data')

### show the last word that was added on the previous run
with open('output/output-original_words.txt', 'r') as file:
lines = file.read().splitlines()
last_word = lines[-1]
# print(last_word) # debug
with open('output/last_word.txt', 'w') as file:
file.write(last_word)

### list cleanup
read_source_file = [x for x in read_source_file if not any(x1.isdigit() for x1 in x)] # remove numbers
read_source_file = [word.replace('\n','') for word in read_source_file] # remove character
Expand Down Expand Up @@ -150,7 +162,7 @@
end_time = time.time() # run time end
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:
print('Nothing new to translate. Exiting...')

Expand Down

0 comments on commit 267e85a

Please sign in to comment.