Skip to content

Commit

Permalink
add basic api call to read calendar events in current month
Browse files Browse the repository at this point in the history
  • Loading branch information
spicydilly committed Sep 19, 2023
1 parent bfae43f commit d4c6e6d
Show file tree
Hide file tree
Showing 6 changed files with 486 additions and 1 deletion.
92 changes: 92 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,93 @@
# daily-event-publisher

## Connect To Google Calendar Using A Service Account

Before continuing, make sure you have a Google Account.

### Project Creation

* Go to the [Google Cloud Console](https://console.cloud.google.com/).
* Click on the project drop-down and then click on NEW `PROJECT`.
* Give your project a name and click `CREATE`.

### Enable Google Calendar API

* In the left sidebar, navigate to `APIs & Services` > `Library`.
* Search for `Google Calendar API` and select it.
* Click `ENABLE`.

### Service Account Creation

* In the left sidebar, navigate to `IAM & Admin` > `Service accounts`.
* Click on `CREATE SERVICE ACCOUNT`.
* Provide a name and description for the service account. Click `CREATE`.
* Grant the service account the required permissions. For basic calendar access, you can choose `Role` > `Google Calendar API` > `Calendar Viewer`. Click `CONTINUE`.
* Click `DONE`.

### Download Credentials

* In the service accounts list, find the service account you just created.
* Click on its name to view details.
* In the `KEYS` tab, click on `ADD KEY` > `JSON`.
* A `credentials.json` file will be downloaded. This file contains the credentials your application will use to authenticate its API requests.

### Share Your Google Calendar

If you're intending to access a specific Google Calendar, make sure to share it with your service account:

* Open [Google Calendar](https://calendar.google.com/).
* Next to your calendar's name, click on the three dots and choose `Settings and sharing`.
* Scroll to the `Share with specific people`` section.
* Click on `+ Add people` and enter the email address of the service account (found in the service account details in Google Cloud Console).
* Set the desired permissions (e.g., `See all event details`) and click `Send`.

## Local Development

### Prerequisites

* **This project requires [Python 3.11](https://www.python.org/downloads/release/python-3113/).**

* Dependencies are managed using [Poetry](https://python-poetry.org/docs/#installation). If you haven't installed it yet, use this command:

```shell
pip install poetry
```

* [Pre-commit](https://pre-commit.com/) is used to enforce code quality. If you don't have pre-commit installed, you can install it using the following command:
```shell
pip install pre-commit
```
### Setting up the Development environment
1. Initialize pre-commit:
```shell
pre-commit install
```
2. Install dependencies and activate the virtual environment:
```shell
poetry install
poetry shell
```
3. The following Environment Variables must exist locally to run this project.
* `GOOGLE_CALENDAR_ID` - The ID of the calendar that is to be read from.
* Go to [Google Calendar](https://calendar.google.com/).
* Choose a Calendar:
* On the left side of the page, you'll see a section titled `My calendars.` These are the calendars associated with your account.
* Hover over the name of the calendar you're interested in. When you do, you'll notice three vertically aligned dots appear to the right of the calendar's name. This is the `Options` menu for that calendar.
* Access Calendar Settings:
* Click on the `Options` (three dots) next to the calendar name.
* From the dropdown menu that appears, select `Settings and sharing`.
* Find the Calendar ID:
* In the settings page, scroll down to the “Integrate calendar” section.
* Here, you'll find a field labeled `Calendar ID`. This is the ID you're looking for. It often looks like an email address and might end with @group.calendar.google.com.
## Refrences
* [Google Calendar API Python documention](https://developers.google.com/calendar/api/quickstart/python).
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__/
.vscode/
.pytest_cache/
credentials.json
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ repos:
rev: 23.3.0
hooks:
- id: black
args: ["--line-length=79", "--experimental-string-processing"]
- repo: https://github.com/hadolint/hadolint
rev: v2.12.0
hooks:
Expand Down
Loading

0 comments on commit d4c6e6d

Please sign in to comment.