Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create GitHub action to update calendar when new entry is added #161

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions update_calendar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import csv
import datetime
from pathlib import Path

from google.oauth2 import service_account
from googleapiclient.discovery import build

SCOPES = [
"https://www.googleapis.com/auth/calendar.events",
"https://www.googleapis.com/auth/calendar",
]

# This calendar ID is public.
CALENDAR_ID = "0ji9k94abd2sehteqqqt4jo47c@group.calendar.google.com"

CURRENT_YEAR = datetime.datetime.now().year


def main():
creds = service_account.Credentials.from_service_account_file(
"credentials.json", scopes=SCOPES
)
service = build("calendar", "v3", credentials=creds)

current_events = (
service.events().list(calendarId=CALENDAR_ID, pageToken=None).execute()
)

with Path(f"{CURRENT_YEAR}.csv").open("r") as csv_file:
csv_reader = csv.DictReader(csv_file, delimiter=",")
csv_events = [row for row in csv_reader]

for event in csv_events:
if event["Subject"] in {
curr_event["summary"] for curr_event in current_events["items"]
}:
continue

py_event_body = {
"summary": event["Subject"],
"location": event["Location"],
"start": {"date": event["Start Date"]},
"end": {"date": event["End Date"]},
"description": event.get("Website URL", ""),
}
python_event = (
service.events()
.insert(calendarId=CALENDAR_ID, body=py_event_body, sendUpdates="all")
.execute()
)
print("Event created: %s" % (python_event.get("htmlLink")))

deadline = event["Talk Deadline"]
if deadline:
talk_event_body = {
"summary": event["Subject"],
"location": event["Location"],
"start": {"date": deadline},
"end": {"date": deadline},
"description": event.get("Website URL", ""),
}
talk_proposal_event = (
service.events()
.insert(calendarId=CALENDAR_ID, body=talk_event_body, sendUpdates="all")
.execute()
)
print("Event created: %s" % (talk_proposal_event.get("htmlLink")))


if __name__ == "__main__":
main()