Giter Site home page Giter Site logo

akarri2001 / notion-and-google-calendar-2-way-sync Goto Github PK

View Code? Open in Web Editor NEW
343.0 16.0 46.0 20.24 MB

2 Way Sync Between Notion Database and Google Calendar

License: GNU General Public License v3.0

Python 99.66% Batchfile 0.13% VBScript 0.21%
notion notion-api notion-database notion-py google-api-python-client google-calendar-api google-calendar notion-automation google-calendar-notion-sync

notion-and-google-calendar-2-way-sync's Introduction

Notion-and-Google-Calendar-2-Way-Sync

2 Way Sync Between a Notion Database and Google Calendar

UPDATE: There seems to be some stuff broken when Notion updated their API again. I'm not going to be able to fix this until the school year is over due to classes but it will be fixed in May 2023 or whenever I'm able to find a full time position.

WARNING: This repo will be undergoing a good bit of change to make more accessible for users of all skill levels. This is not a finished product and if you have suggestions, I would love them!

REMINDER: No making monetary gain off of this product. The point of making this available was to make the tools accessible to everyone

Instructions to set up: https://docs.google.com/document/d/1uP-6EsmTlG_Gttg9jC0MBZKHpjccVapIeC1D1tR1yXc/edit?usp=sharing

NEW FUNCTIONALITIES SINCE FIRST UPLOADING:

  • Option to delete gCal events if checked off as Done in Notion
  • Sync across multiple calendars and choose which calendar you would like to sync
  • Able to name the required Notion columns whatever you want and have the code work
  • Able to add in end times and sync that across both platforms
  • Able to decide if a date in Notion will make an event at a desired time or if it will make an All-day event
  • Ability to change timezones a lot easier
  • Able to decide default length of new GCal events

I'm not sure if this is the first one out there, but it is the only 2-way synchronous project I could find so that's pretty cool :)

The Notion-GCal-2WaySync-Public.py code is HEAVILY commented to describe each part of the code. Follow along and you'll be able to get a quick understanding of what logic is used for each step of the script. Use this Notion Template as reference: https://www.notion.so/akarri/de7bcf954c8847a4952202b93fab2dad?v=23e8972499124b5c84b67b9e08d0cc2c (multiple calendar)

https://www.notion.so/akarri/47c0977120094511b0ab6cbf68b20c57?v=21c35762ede544818692acb1e8deefed (single calendar code (outdated))

The functionalities:

  • Take existing events from your Notion Dashboard and bring them over to Google Calendar
  • If the Notion event has only a date, then the GCal event is made at 8 am (option to turn this off and have the event be all day instead)
  • If the Notion even has a date and time, then the GCal event is made at the appropriate time
  • If the event is already in both GCal and Notion, but you switch the date/time on either, it will sync with the new value across both platforms (if both are changed, the value on Notion will overrule).
  • If the event is only in GCal, it will be brought over to Notion, as well as the description of the event that you add from GCal

When making events, the code will extract the event name, date/time, a category, and text from the Notion Dashboard and integrate that information into your GCal event. Additionally, it will also add a URL source code the GCal event so you can click on the URL and automatically be brought over to the specific Notion Page that your event is at.




Future Updates (dates subject to change)

  • Able to name the required Notion columns whatever you want and have the code work (By June 5th) ✅ (Done)
  • Able to add in end times and sync that across both platforms (by June 15th) ✅ (Done)
  • Able to add different events to different calendars depending on a Notion column (up in the air) ✅ (Done)
  • Able to factor in recurring events (up in the air) (the way GCal API handles recurring events really funky, so help would be appreciated!)

Some more visibility through some upvotes on my Reddit post would be appreciated and I think may bring along some new users to this resource! Reddit Post

Use for those who want to take at implementing the code themselves:

https://www.youtube.com/watch?v=j1mh0or2CX8 This video was used to make the Google Calendar token. Note that the library names that they "pip installed" are outdated so look at the python file to see what you'll actually need to pip install onto your computer.

The Google Calendar token is what allows for the python code to access your Google Calendar and communicate with the Google Calendar servers to add/receive/modify data.

You'll need to make your GCal token before setting up the rest of the Python script. Use the GCalToken.py file to create your token when you have downloaded the JSON credentials (follow the above youtube video).

notion-and-google-calendar-2-way-sync's People

Contributors

akarri2001 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

notion-and-google-calendar-2-way-sync's Issues

googleapi calendar_id has changed

Hi,
I am unable to find my calendar id. It appears as for the "main" calendar, the calendar id is just the email address, ie "[email protected]"
Thus I'm unable to plug the id in the code.
Someone was able to integrate the script with their "main" calendar?

Any help?
Thanks

Notion client

When I run the code.
It shows the following

ModuleNotFoundError: No module named 'notion_client'

I have installed notion and also no other file named notion.py, so I don't know how to solve that.

The second error is that "GCalTokenLocation is not defined"
I have put my notion token string in the NOTION_TOKEN(line 15)

Cannot run the file

I did exactly what the tutorial says but when I run "python3 Notion-GCal-2WaySync-Public.py" it says the following.
What should I do now?

  File "/home/lelouvincx/.local/lib/python3.9/site-packages/notion_client/client.py", line 83, in _parse_response
    response.raise_for_status()
  File "/home/lelouvincx/.local/lib/python3.9/site-packages/httpx/_models.py", line 1105, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: 404 Client Error: Not Found for url: https://api.notion.com/v1/databases/3b58b006436c477e85c500fb2a41152f/query
For more information check: https://httpstatuses.com/404

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/lelouvincx/Documents/NotionXGCalendar/Notion-GCal-2WaySync-Public.py", line 394, in <module>
    my_page = notion.databases.query(  #this query will return a dictionary that we will parse for information that we want
  File "/home/lelouvincx/.local/lib/python3.9/site-packages/notion_client/api_endpoints.py", line 46, in query
    return self.parent.request(
  File "/home/lelouvincx/.local/lib/python3.9/site-packages/notion_client/client.py", line 133, in request
    return self._parse_response(response)
  File "/home/lelouvincx/.local/lib/python3.9/site-packages/notion_client/client.py", line 93, in _parse_response
    raise APIResponseError(error.response, body)
notion_client.errors.APIResponseError: Could not find database with ID: 3b58b006-436c-477e-85c5-00fb2a41152f.```

Problem bringing GCal events to Notion

Notion feeds GCal perfectly, but when I run Part 4: Bring events (not in Notion already) from GCal to Notion it gives me this error:
File "Notion-GCal-2WaySync-Public.py", line 1253, in
calName = [item['summary'] for item in calItems]
File "Notion-GCal-2WaySync-Public.py", line 1253, in
calName = [item['summary'] for item in calItems]
KeyError: 'summary'
I'm kinda a python newbie, so I'd be grateful for any help ;)

End Time Notion not appearing in GCal

Hey! Thank you so much for this project! This is exactly what I have been looking for.

I however encouter a problem with the endtimes of events in Notion. If I've read it correctly in the added features you have mentioned that endtimes should be synced both ways. This works when I create an event in GCal; it shows up correctly. But if I enter an endtime in Notion it ends up with the default 60 minutes duration in GCal.

Do I have to adjust something in the code to make this work? I have read the code from top to bottom but can't seem to find the place where this should be adjusted.

Problem creating token.pkl file in iOS

Hi,
Thank you very much for your work! Once i get it working, it will make a huge difference in my personal organization. When I hit enter after typing "python3 GCalToken.py" (step 19b, iOS), nothing happens so I can't get the URL necessary to move forward.
Anyone know what I might be doing wrong? I saw a few reddit comments describing a similar issue.

Thanks!

ValueError and 404Error GoogleAPI

ValueError and 404Error GoogleAPI

HttpError 404 when requesting (https://www.googleapis.com/calendar/v3/calendars)

File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\googleapiclient\http.py", line 935, in execute raise HttpError(resp, content, uri=self.uri) googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/calendar/v3/calendars/6cw0v*************group.calendar.google.com/events/7b52796dfobjgijp9vlv8cf80s/move?destination=fd34893uklhjdflgkjsdafdfjklsd%40group.calendar.google.com&alt=json returned "Not Found". Details: "[{'domain': 'global', 'reason': 'notFound', 'message': 'Not Found'}]">

and
During handling of the above exception, another exception occurred:

ValueError("unconverted data remains: %s":

File "C:\Users\User\***\Notion-and-Google-Calendar-2-Way-Sync-main/Notion-GCal-2WaySync-Public.py", line 762, in <module> calEventId = upDateCalEvent(TaskNames[i], makeEventDescription(Initiatives[i], ExtraInfo[i]), datetime.strptime(start_Dates[i], '%Y-%m-%d'), URL_list[i], updatingCalEventIds[i], datetime.strptime(end_Times[i], '%Y-%m-%d'), CurrentCalList[i], CalendarList[i]) File "C:\Users\User\AppData\Local\Programs\Python\Python3.9/_strptime.py", line 568, in _strptime_datetime tt, fraction, gmtoff_fraction = _strptime(data_string, format) File "C:\Users\User\AppData\Local\Programs\Python\Python3.9/_strptime.py", line 352, in _strptime raise ValueError("unconverted data remains: %s" % ValueError: unconverted data remains: [T00:00:00.000+02:00](url)

events organised by others cause crash

Hello,
Thank you for your work!
I noticed that when I accept events' invitations in google calendar, the code exits with an error saying that the email of the event organiser is not "on list" and exiting the execution of the script, without synching any further events. It also refers to line 1259. It seems like a default calendar should be set to sync such events into.
Would be very thankful for your help!

File Not Found Error

Hi! For some reason, the credentialsLocation is giving me a FileNotFoundError for my token.pkl. I switched the slashes and even did a quick print on os.path.isfile("token.pkl") and it returned True. Any tips? Thanks!

notion_gCal_IDs.append: List index out of range

I just set up your script and can't figure out what's wrong from this error. May you help?

❯ python3 ./Notion-GCal-2WaySync-Public.py 

Nothing new added to GCal
Nothing new updated to GCal
Traceback (most recent call last):
  File "/home/blue/Downloads/Notion-and-Google-Calendar-2-Way-Sync/./Notion-GCal-2WaySync-Public.py", line 841, in <module>
    notion_gCal_IDs.append(result['properties'][GCalEventId_Notion_Name]['rich_text'][0]['text'])
IndexError: list index out of range

TaskNames.append(el['properties'][Task_Notion_Name]['title'][0]['text']['content']) KeyError: 'title'

Hey @akarri2001. This is an amazing project but I'm unable to run it because of so many errors. I followed the docs and changed the token etc. Kindly fix this error. If possible can you make YouTube Tutorial on How to configure this project step by step because from docs I got stuck in between. Thank you

Traceback (most recent call last):
File "E:\Python Work\Notion & Google calender\Notion-and-Google-Calendar-2-Way-Sync\Notion-GCal-2WaySync-Public.py", line 738, in
TaskNames.append(el['properties'][Task_Notion_Name]['title'][0]['text']['content'])
KeyError: 'title'

TypeError: string indices must be integers

Notion-GCAl-Sync Iccue

The above error occurs when I run the script while Google Calendar is syncing tasks (not already in my Notion database) to my Notion database. Can't seem to figure out the issue.

Traceback Error - Index Error: List Index out of Range

Traceback (most recent call last):
File "C:\Users\User\Downloads\Notion-and-Google-Calendar-2-Way-Sync\Notion-GCal-2WaySync-Public.py", line 728, in
CurrentCalList.append(el['properties'][Current_Calendar_Id_Notion_Name]['rich_text'][0]['text']['content'])
IndexError: list index out of range

I always get this error when running the python, but the code works except for syncing my second calendar. Both calendars are mine.

P.S.
I don't think it's a bug but I needed help so posted this here.

HttpError 400, Bad Request when trying to obtain events info

Hi,

My code successfully pushes events from Notion to gcal but not the other way around. The code receives a bad request at line 1247 i.e., x = service.events().list(calendarId = calendarDictionary[el], maxResults = 2000, timeMin = googleQuery() ).execute()

I have checked that the calendar id is correct. Please could anyone help?
Thanks

Access blocked

after pasting the link created with the gcaltoken.py google gives me this message

"Access blocked: NOTION GCAL SYNC has not completed the Google verification process
NOTION GCAL SYNC has not completed the Google verification process. The app is currently being tested, and can only be accessed by developer-approved testers. If you think you should have access, contact the developer.
If you are a developer of NOTION GCAL SYNC, see error details.
Error 403: access_denied"
i cheked every step, and did exactly as the instruccion said

ValueError("unconverted data remains: %s" and HttpError 404 when requesting https://www.googleapis.com/calendar/v3/calendars

I receive following errors:
1)File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/_strptime.py", line 352, in _strptime
raise ValueError("unconverted data remains: %s" %
ValueError: unconverted data remains: T13:00:00.000-04:00

  1. File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/googleapiclient/http.py", line 935, in execute
    raise HttpError(resp, content, uri=self.uri)
    googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/calendar/v3/calendars/3cq0v2l8n197dmrie8l7vhjlj0%40group.calendar.google.com/events/3p10s2o3lst5mhtfkv3v23mvt4/move?destination=njgl69md8r5ckbspstljs3bqug%40group.calendar.google.com&alt=json returned "Not Found". Details: "[{'domain': 'global', 'reason': 'notFound', 'message': 'Not Found'}]">

Can anybody help?

Existing tasks will be duplicated if there are more than 100 tasks in Notion's database

Thanks again for the great code.

Now, when I was running this code, it sometimes generated duplicate tasks in the database.
Apparently, there is a problem with the procedure in Part 4 that looks for calendar events that don't exist in Notion.

my_page = notion.databases.query( **{ "database_id": database_id, "filter": { "property": GCalEventId_Notion_Name, "text": { "is_not_empty": True } } }, )

In the Notion API, query responses are limited to 100 at a time.
If there are more than 101 tasks, the IDs contained in the 101st task will not be used for comparison.
Therefore, the program will overlook the IDs that should already be there, so it will add a new column of Notion.

I can't think of a solution right away, so I'll post it in an issue.

GCalToken.py

File "C:\CalendarSync\GCalToken.py", line 1, in
from googleapiclient.discovery import build
ModuleNotFoundError: No module named 'googleapiclient'

Error

` File "C:\Users\User\Desktop\Coding_Projects\NotionXGCal\Notion-GCal-2WaySync-Public.py", line 759, in
calEventId = upDateCalEvent(TaskNames[i], makeEventDescription(Initiatives[i], ExtraInfo[i]), datetime.strptime(start_Dates[i], '%Y-%m-%d'), URL_list[i], updatingCalEventIds[i], datetime.strptime(end_Times[i], '%Y-%m-%d'), CurrentCalList[i], CalendarList[i])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\User\Desktop\Coding_Projects\NotionXGCal\Notion-GCal-2WaySync-Public.py", line 374, in upDateCalEvent x= service.events().move(calendarId= currentCalId , eventId= eventId, destination=CalId).execute()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\googleapiclient_helpers.py", line 134, in positional_wrapper
return wrapped(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\googleapiclient\http.py", line 935, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/calendar/v3/calendars/3cq0v2l8n197dmrie8l7vhjlj0%40group.calendar.google.com/events/7b52796dfobjgijp9vlv8cf80s/move?destination=fd34893uklhjdflgkjsdafdfjklsd%40group.calendar.google.com&alt=json returned "Not Found". Details: "[{'domain': 'global', 'reason': 'notFound', 'message': 'Not Found'}]">

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\User\Desktop\Coding_Projects\NotionXGCal\Notion-GCal-2WaySync-Public.py", line 762, in
calEventId = upDateCalEvent(TaskNames[i], makeEventDescription(Initiatives[i], ExtraInfo[i]), datetime.strptime(start_Dates[i][:-6], "%Y-%m-%dT%H:%M:%S.000"), URL_list[i], updatingCalEventIds[i], datetime.strptime(end_Times[i][:-6], "%Y-%m-%dT%H:%M:%S.000"), CurrentCalList[i], CalendarList[i])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data '2023' does not match format '%Y-%m-%dT%H:%M:%S.000'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\User\Desktop\Coding_Projects\NotionXGCal\Notion-GCal-2WaySync-Public.py", line 764, in
calEventId = upDateCalEvent(TaskNames[i], makeEventDescription(Initiatives[i], ExtraInfo[i]), datetime.strptime(start_Dates[i][:-6], "%Y-%m-%dT%H:%M:%S.%f"), URL_list[i], updatingCalEventIds[i], datetime.strptime(end_Times[i][:-6], "%Y-%m-%dT%H:%M:%S.%f"), CurrentCalList[i], CalendarList[i])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data '2023' does not match format '%Y-%m-%dT%H:%M:%S.%f'

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.