Guest User

Untitled

a guest
Jan 15th, 2019
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. """
  2. Reads in the export file from FBReader and imports your notes / bookmarkes / quotes to evernote.
  3.  
  4. It's done by sending a mail to your evernote-mail which then creates a note in your default notebook.
  5. It creates one evernote note per quote. Each titled with the book title.
  6. Additionally, it creates an optional summary note, which contains all quotes from the given book.
  7.  
  8. To use, fill out the settings variables below.
  9. """
  10.  
  11. import os
  12. import smtplib
  13.  
  14. import click
  15. from tqdm import tqdm
  16.  
  17. EVERNOTE_MAIL = 'xxx@m.evernote.com'
  18. FROM_MAIL = 'xxx@gmail.com'
  19. SMTP_HOST = 'smtp.gmail.com'
  20. SMTP_PORT = 587
  21. SMTP_USER = 'xxx@gmail.com'
  22. SMTP_PASSWORD = '' # Create an app password in case of using gmail
  23.  
  24. @click.command()
  25. @click.argument('textfile')
  26. @click.argument('book_title')
  27. def create_notes(textfile, book_title):
  28. if not os.path.isfile(textfile):
  29. raise click.UsageError('The specified textfile does not exist')
  30.  
  31. with open(textfile, 'r') as f:
  32. notes = f.read().split('\n\n')
  33.  
  34. click.echo(f'{len(notes)} notes found.')
  35. click.confirm('Do you want to continue?', abort=True)
  36.  
  37. server = smtplib.SMTP(SMTP_HOST, SMTP_PORT)
  38. server.starttls()
  39. server.login(SMTP_USER, SMTP_PASSWORD)
  40.  
  41. progress_bar = tqdm(total=len(notes))
  42.  
  43. for note in notes:
  44. note_title = book_title
  45. note_content = note.strip()
  46. message = 'Subject: {}\n\n{}'.format(note_title, note_content)
  47. server.sendmail(FROM_MAIL, EVERNOTE_MAIL, message)
  48. progress_bar.update(1)
  49.  
  50. if click.confirm('Do you want to create one additional note which contains all quotes?'):
  51. note_title = f'{book_title} - All Quotes / Summary'
  52. note_content = f'In total you made {len(notes)} notes in {book_title}\n\n'
  53. note_content += '\n\n'.join(notes)
  54. message = 'Subject: {}\n\n{}'.format(note_title, note_content)
  55. server.sendmail(FROM_MAIL, EVERNOTE_MAIL, message)
  56.  
  57. progress_bar.close()
  58.  
  59. server.quit()
  60.  
  61. if __name__ == '__main__':
  62. create_notes()
Add Comment
Please, Sign In to add comment