Python script for syncing Google Play Books Highlights to Notion
- Books2Notion
Red highlights are reserved for saving new words, it gets added to 'New Words' database along with definition fetched from Wiktionary
append
- appends new highlights and new words to notion, but won't sync highlights and new words from pages that have been synced beforesync
- syncs complete highlights of the books to notionsync-full
- syncs complete highlights and new words
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.
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
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
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
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.
Duplicate books template and share -> invite -> integration_name -> invite
Goto https://console.cloud.google.com/ then click 'select a project'
Give the project a name and click create
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
Download file and save it as credentials.json
in the books2notion
folder we created in 1. Clone Git repo
We have to enable Books API
, Google Drive API
and Google Docs API
Search for each APIs mentioned above and enable it
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
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
goto https://freeimage.host/page/api?lang=en and save the api key somewhere
goto https://www.timeanddate.com/time/zone/ and find time offset from UTC
Example +05:30
,-04:00
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=
goto https://heroku.com/ and make a free account
https://devcenter.heroku.com/articles/heroku-cli#install-the-heroku-cli
heroku login
heroku create
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
croll down and you will find option to add buildpack
git push heroku deployment:main
Go to resources and toggle on dyno
Now that's it, we have successfully deployed application.
Sheduling locally in Mac and Linux (cron)
Follow this article
Sheduling locally in Windows (windows task scheduler)
Follow this article