Git Product home page Git Product logo

books2notion's Introduction

Books2Notion

Python script for syncing Google Play Books Highlights to Notion

Google Play Books Notion Notes


Table of Contents


Usage

Red highlights are reserved for saving new words, it gets added to 'New Words' database along with definition fetched from Wiktionary

Sync Modes

  1. append - appends new highlights and new words to notion, but won't sync highlights and new words from pages that have been synced before
  2. sync - syncs complete highlights of the books to notion
  3. sync-full - syncs complete highlights and new words

Automatic

Follow 7. Schedule script to schedule .Script is scheduled to run every hour in append mode. Enable Full_Sync checkbox for books in the database if you want to run the script in sync-full mode in the next scheduled run.

Run Manually

Clone manual branch

git clone --single-branch --branch manual https://github.com/MohamedIrfanAM/books2notion.git
python3 books2notion.py --mode <mode>

Example: python3 books2notion.py --mode sync-full

Installation and Setup

1. Clone Git repo

Make sure you have git installed. To schedule script, clone deployment branch

git clone https://github.com/MohamedIrfanAM/books2notion.git

For running the script manually, clone manual branch

git clone --single-branch --branch manual https://github.com/MohamedIrfanAM/books2notion.git

2.Install Python Modules

Install Python and proceed to install following modules

pip install --upgrade google-api-python-client, google-auth-httplib2, google-auth-oauthlib
pip install Pillow
pip install schedule

3.Authorize Notion

a. Get Notion Integration Token

Goto https://www.notion.so/my-integrations and make an integration, give it a name submit with default settings.


Copy the integration token and save it somewhere.

b. Duplicate template and share it to integration

Duplicate books template and share -> invite -> integration_name -> invite


4. Authorize Google APIs

a. Create Google cloud project

Goto https://console.cloud.google.com/ then click 'select a project'

Give the project a name and click create

b. Create OAuth consent screen

Fill 'name' and 'user support email'

Scroll down fill in 'Email address' and continue

click 'save and continue' for 'Scopes' and 'Test Users', don't have to fill in anything

Publish app

c. Create OAuth2.0 credentials

Download file and save it as credentials.json in the books2notion folder we created in 1. Clone Git repo

d. Enable APIs

We have to enable Books API, Google Drive API and Google Docs API

Search for each APIs mentioned above and enable it

5. Get env variables

a. Get NOTION_DATABASE_ID

Copy the url of database we duplicated in Duplicate Notion template
It should look like this

https://www.notion.so/lucas-gen/e32a031992f348aeae115fe6dee8353?v=1e75f5e2b07349f4b331e88c4ca3beac


Save the databse id somewhere

b. Get DRIVE_FOLDER_ID

Select any book from your Play Books library and open to read, you will find an option to save annotations to google drive and enable it (only have to doit once,then it will be default for everybook).

Go to google drive and navigate to folder you selected for saving annotations and copy it's url.
it should look like this - https://drive.google.com/drive/folders/<folder id>
copy the folder id and save it somewhere

c. Get IMAGE_HOST_KEY

goto https://freeimage.host/page/api?lang=en and save the api key somewhere

d. Get TIME_OFFSET

goto https://www.timeanddate.com/time/zone/ and find time offset from UTC
Example +05:30,-04:00

6. Authorize script

Run the script for the first time python3 schedule_sync.py in the terminal, you will prompted to give access to application via browser. This script will create a .env file in books2notion folder. You don't have to authorize everytime just first time only.
The .env file generated by running above script should look something like this

API_TOKEN=<google API token, filled by script>
REFRESH_TOKEN=<google refresh token, filled by script>
TOKEN_URI=<token URI, filled by script>
CLIENT_ID=<client id, filled by script>
CLIENT_SECRET=<client id, filled by script>
EXPIRY=<token expiry, filled by script>
NOTION_KEY=
NOTION_DATABASE_ID=
DRIVE_FOLDER_ID=
IMAGE_HOST_KEY=
TIME_OFFSET=

7. Schedule script

Heroku

a. Create Heroku Account

goto https://heroku.com/ and make a free account

b. Install Heroku cli

https://devcenter.heroku.com/articles/heroku-cli#install-the-heroku-cli

c. Heroku login
heroku login
d. Create app
heroku create
e. Fill env variables

goto https://dashboard.heroku.com/apps and you find your app, it might not be named books2notion

goto settings

Reveal config vars

Fill in env variables we saved from 3. Get Notion Integration Token, 5. Get env variables, 6. Authorize script

f. add buildback

croll down and you will find option to add buildpack

g. deploy application
git push heroku deployment:main
h. start dyno

Go to resources and toggle on dyno

Now that's it, we have successfully deployed application.

Local

Sheduling locally in Mac and Linux (cron)
Follow this article
Sheduling locally in Windows (windows task scheduler)
Follow this article

books2notion's People

Contributors

mohamedirfanam avatar

Stargazers

 avatar  avatar Jose Miguel Reyes avatar HAWii avatar Bagas Wastu avatar  avatar Alvaro Quinteros avatar Akhmad Rizki Triandani avatar  avatar lacy avatar jnagler avatar Alex avatar Isabel avatar Je Sian Keith Herman avatar Weiyong Xu avatar  avatar Deep avatar  avatar

Watchers

 avatar

books2notion's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.