GithubHelp home page GithubHelp logo

notion2googlecal's Introduction

Notion to Google Calendar Integration

This script utilizes the unofficial Notion API and the Google Calendar API to sync a calendar directly between Notion and Google Calendar. Set this up as a cron job to have it sync changes between calendars automatically!

Set-up the Script:

  1. Clone the github repo and open up main.py. In here, you'll find a list of set-up variables you'll want to provide values for: your Notion token (retrieved from a cookie), the URL of the Notion calendar you'd like to use, your timezone, and the calendar ID of the Google Calendar you want to use. Here's how to get these things:

    a) Notion token: Open the notion workspace for the calendar you want to sync in your browser. Open the developer console using Inspect. Tab over to Application and select the Cookies sub-menu. Look for the cookie named token_v2 and copy its value. In main.py, set notion_token equal to this value as a string.
    b) Notion calendar: Navigate to the notion calendar you want to sync and copy the link. Make sure it's shareable so that it's viewable by anyone. In main.py, set notion_cal equal to this value as a string.
    c) Timezone: Again in main.py, set timezone equal to the timezone of your Notion calendar. Format your timezone according to your timezone's TZ database name, found here.
    d) Google Calendar: Navigate to the settings page for the google calendar that you have edit access to that you want to sync. Scroll down to the Integrate calendar section, and find the Calendar ID. In main.py, set calendar_id equal to this value as a string.

  2. In your Notion, open the menu bar (indicated by three dots in the top right corner of the calendar view. Click properties, and add a property titled last edited with an advanced type of last edited time.

  3. Add any additional event properties you have in the script in the try-catch block around line 100 if you want to include extra things like location, description, etc.

  4. Follow the first step of this google calendar quickstart by clicking Enable the Google Calendar API. Name your project and click NEXT. Select Desktop App to Configure your OAuth Client. Then, obtain your credentials.json file by clicking DOWNLOAD CLIENT CONFIGURATION. Add the file to your project workspace, and set the value of credentials_file to the name of this file as a string. You will need this in order to later authenticate your account and obtain your Google Calendar data.

  5. Run the script locally on your computer. The first time this script is run, you will be taken through Google's authentication flow. Sign in with the account that owns the Google Calendar whose ID you used.

Your calendars should now be sucessfully synced! You can continue to run your script whenever you want the calendars to resync, or continue with setting up a cron job to have this process happen automatically!


Set-up the Cron Job:

  1. Install Google Cloud Command Line Tools (skip if you already have)

    You will need to initialize GCloud's SDK in order to deploy the script. Download the SDK here and follow the instructions to initialize.

  2. Create a Cloud Function:
    Navigate to Google Cloud Platform. On the dashboard for your new project, open Go to APIs Overview, and click ENABLE APIS AND SERVICES. Search for and enable the Google Build API and Google Calendar API. Next, navigate back to the API & Services home page, and into the Credentials tab. In the Service Accounts section, there should be an App Engine default service account already created. Copy the email address, go to Settings and sharing for the Google Calendar you want synced, and share the calendar with the service account, providing it permission to Make changes.

    Open the terminal on your computer and navigate to the folder the main.py script is located in. Run the following command in your terminal: gcloud functions deploy main --trigger-http --runtime=python37 --project=INSERT_PROJECT_ID, replacing INSERT_PROJECT_ID with your project's ID. This value should be available in the Project info section of your Google Cloud Platform Dashboard. When the command runs, it should provide you the option to run authenticated/allow unauthenticated. Make sure to allow unauthenticated, and the function should take a few minutes to deploy to your Google Cloud Console. Once it has successfully deployed, you can schedule it to run as often as you'd like!

  3. Schedule Cloud Function as a Cron Job: Again, open the menu bar on the left side of the page and navigate to Cloud Scheduler under TOOLS. Click CREATE JOB.

    a) Fill out the space for Name.
    b) Fill out the rule for Frequency according to how often you want the script to be run. We use "* * * * *" to indicate the cron job would run every minute.
    c) Fill out the space for Timezone. For our frequency, it didn't matter what the timezone was, but if you want your script to run at a more specific time (ie. everyday @ 3pm), consider this in selecting your timezone.
    d) Change Target to be HTTP.
    e) Insert the URL to send a request to. This is the URL that was returned from deploying the cloud function.
    f) Click CREATE.

    It may take a few minutes to set-up, but the script should now automatically run according to the frequency rule you selected.

Warnings

  1. Timezones: From testing, using os.environ["TZ"] does not work on windows computers. If you plan to use this calendar with people in other timezones, they must manually configure the timezone of the event that they add in the Notion calendar to match the timezone of the person who created the calendar.
  2. Recurring Events: Syncing a calendar with recurring events will remove the recurrence rule property from events in google calendar. Since notion does not allow for specifying IDs, we are unable to maintain sync while also upholding the requirements for google calendar IDs and RecurringEventIDs. Syncing will still display all recurring and non-recurring events on your calendar, but will not maintain the recurrence rule property of recurring google calendar events.

We Need Help!

This script is far from perfect, and we're trying to make the script as efficient as possible to minimize the rate at which Google Calendar's API is called as well as the number of times it needs to be called.

Setting up the script as a cron job will cause a violation in the rate limit beyond a calendar of ~120 events, which is not a lot.

notion2googlecal's People

Contributors

maximgeller avatar samjaehnig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

notion2googlecal's Issues

CalendarID missing required parameter

Hi, i've added in my calendar id (tried multiple) in the variables but when I run the code after successfully authorizing it says that I'm missing required parameter "calendarID" even though I've inserted it (as a string) there.

Invalid Input

Hello!

I followed all the setup instruction, installed the dependencies, authorise the application ...
When I run the script, I have this error which seems to be related to notion dependency:

Traceback (most recent call last):
  File "/Users/user/notion2googlecal/main.py", line 326, in <module>
    main("request")
  File "/Users/user/notion2googlecal/main.py", line 82, in main
    notion_events = calendar.collection.get_rows()
  File "/usr/local/lib/python3.9/site-packages/notion/collection.py", line 178, in get_rows
    return self.query(**kwargs)
  File "/usr/local/lib/python3.9/site-packages/notion/collection.py", line 175, in query
    return CollectionQuery(self, self._get_a_collection_view(), **kwargs).execute()
  File "/usr/local/lib/python3.9/site-packages/notion/collection.py", line 314, in execute
    self._client.query_collection(
  File "/usr/local/lib/python3.9/site-packages/notion/client.py", line 217, in query_collection
    return self._store.call_query_collection(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/notion/store.py", line 338, in call_query_collection
    response = self._client.post("queryCollection", data).json()
  File "/usr/local/lib/python3.9/site-packages/notion/client.py", line 183, in post
    raise HTTPError(
requests.exceptions.HTTPError: Invalid input.

Do you know how I could save this problem ? I would be more than happy to help for the investigation.

Thanks !

TypeError and AttributeError

  1. TypeError

Traceback (most recent call last):
File "/Users/harry/Documents/Notion Google calander intergration/notion2googlecal-master/main.py", line 326, in
main("request")
File "/Users/harry/Documents/Notion Google calander intergration/notion2googlecal-master/main.py", line 64, in main
events_result = service.events().list(calendarId=calendar_id,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/googleapiclient/discovery.py", line 1018, in method
raise TypeError('Missing required parameter "%s"' % name)
TypeError: Missing required parameter "calendarId"

The above error shows when line 64 is the following
events_result = service.events().list(calendarId=calendar_id,

The bug disappear when I replace the "calendar_id" to the actual calendar id found in Google Calendar.

  1. AttributeError
    The programme ask for the notion account and password, after typing it in the console, the following appears:

Traceback (most recent call last):
File "/Users/harry/Documents/Notion Google calander intergration/notion2googlecal-master/main.py", line 326, in
main("request")
File "/Users/harry/Documents/Notion Google calander intergration/notion2googlecal-master/main.py", line 79, in main
calendar = client.get_collection_view(notion_cal)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/notion/client.py", line 211, in get_collection_view
if url_or_id.startswith("http"):
AttributeError: 'NoneType' object has no attribute 'startswith'

I can't solve the problem, and hope you can help me.

Thank you very much. :) Harry

If you wanna contact me via email, [email protected]

HTTP 400 error

I have everything setup as described but for some reason I keep getting this error when trying to sync. If you have any ideas how to fix it plz help! Really wanna get this to work.
Screen Shot 2021-05-08 at 1 39 43 PM

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.