Last active
January 15, 2019 20:10
-
-
Save mammuth/1c8480aea56efe89b3f4791ba30185ac to your computer and use it in GitHub Desktop.
Export book quotes/notes from FBReader to Evernote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Reads in the export file from FBReader and imports your notes / bookmarkes / quotes to evernote. | |
It's done by sending a mail to your evernote-mail which then creates a note in your default notebook. | |
It creates one evernote note per quote. Each titled with the book title. | |
Additionally, it creates an optional summary note, which contains all quotes from the given book. | |
To use, fill out the settings variables below. | |
""" | |
import os | |
import smtplib | |
import click | |
from tqdm import tqdm | |
EVERNOTE_MAIL = '[email protected]' | |
FROM_MAIL = '[email protected]' | |
SMTP_HOST = 'smtp.gmail.com' | |
SMTP_PORT = 587 | |
SMTP_USER = '[email protected]' | |
SMTP_PASSWORD = '' # Create an app password in case of using gmail | |
@click.command() | |
@click.argument('textfile') | |
@click.argument('book_title') | |
def create_notes(textfile, book_title): | |
if not os.path.isfile(textfile): | |
raise click.UsageError('The specified textfile does not exist') | |
with open(textfile, 'r') as f: | |
notes = f.read().split('\n\n') | |
click.echo(f'{len(notes)} notes found.') | |
click.confirm('Do you want to continue?', abort=True) | |
server = smtplib.SMTP(SMTP_HOST, SMTP_PORT) | |
server.starttls() | |
server.login(SMTP_USER, SMTP_PASSWORD) | |
progress_bar = tqdm(total=len(notes)) | |
for note in notes: | |
note_title = book_title | |
note_content = note.strip() | |
message = 'Subject: {}\n\n{}'.format(note_title, note_content) | |
server.sendmail(FROM_MAIL, EVERNOTE_MAIL, message) | |
progress_bar.update(1) | |
if click.confirm('Do you want to create one additional note which contains all quotes?'): | |
note_title = f'{book_title} - All Quotes / Summary' | |
note_content = f'In total you made {len(notes)} notes in {book_title}\n\n' | |
note_content += '\n\n'.join(notes) | |
message = 'Subject: {}\n\n{}'.format(note_title, note_content) | |
server.sendmail(FROM_MAIL, EVERNOTE_MAIL, message) | |
progress_bar.close() | |
server.quit() | |
if __name__ == '__main__': | |
create_notes() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment