This Python application automates the scheduling of instructor-led courses into Google Calendar. It supports recurring weekly sessions, rotating Saturday assignments, holiday handling, instructor-based color coding, and uses the Google Calendar API for event creation.
- Weekly scheduling for Monday, Tuesday, Thursday, and Saturday
- Rotating Saturday instructors
- Automatically skips holidays and shifts sessions forward
- Color-coded events per instructor
- OAuth2 authentication with token caching
- Secure credential management using
.env
git clone https://github.com/zagui440s/calendar_app.git
cd calendar_app
2. Create and Activate a Virtual Environment
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate
3. Install Dependencies
pip install -r requirements.txt
google-api-python-client
google-auth
google-auth-oauthlib
python-dotenv
4. Google Calendar API Setup
4A. Create a New Project
IAM & Admin → Create Project
Project Name example: my-calendar-app, then click Create
4B. Enable the Calendar API
Navigation Menu → APIs & Services → Library
Under Google Workspace, select Google Calendar API
Click Enable
5. Configure OAuth Consent Screen
Navigation Menu → APIs & Services → OAuth Consent Screen
Choose External and click Create
Enter app name and support email
Add your own email under Developer Contact
Click through and Publish
6. Create OAuth Credentials (OAuth Client ID)
APIs & Services → Credentials → Create Credentials
Choose OAuth client ID → Desktop App
Name it and click Create
Click Download JSON and rename the file to credentials.json
Place credentials.json in the project root
7. Create .env File
Create a .env file in your root folder and add:
# Google API credentials
GOOGLE_CLIENT_ID=your_client_id_here
GOOGLE_CLIENT_SECRET=your_client_secret_here
GOOGLE_PROJECT_ID=your_project_id_here
GOOGLE_REDIRECT_URI=http://localhost:8000
# Instructor Aliases and Assigned Days
INSTRUCTOR_ALIAS_1=instructor_name
INSTRUCTOR_DAY_1=Monday
INSTRUCTOR_ALIAS_2=instructor_name
INSTRUCTOR_DAY_2=Tuesday
INSTRUCTOR_ALIAS_3=instructor_name
INSTRUCTOR_DAY_3=Thursday
INSTRUCTOR_ALIAS_4=instructor_name
INSTRUCTOR_DAY_4=floater
IMPORTANT: Add .env and credentials.json to your .gitignore so they aren't uploaded to GitHub.
8. Add Test Users (for Development)
In OAuth Consent Screen → Test Users → Add your email address
Running the App
The default action is to create calendar events.
python schedule.py
To delete the course events instead:
Open schedule.py
Change this line:
ACTION = "create"
TO
ACTION = "delete"
Then re-run
python schedule.py
Full Google Calendar color reference:
1: Lavender 2: Sage 3: Grape
4: Flamingo 5: Banana 6: Tangerine
7: Peacock 8: Graphite 9: Blueberry
10: Basil 11: Tomato
Verify Google Calendar API Connection
Use this snippet to list your calendars:
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
SCOPES = ['https://www.googleapis.com/auth/calendar']
def main():
creds = None
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
service = build('calendar', 'v3', credentials=creds)
calendars_result = service.calendarList().list().execute()
calendars = calendars_result.get('items', [])
print('Your calendars:')
for calendar in calendars:
print(f"- {calendar['summary']}")
if __name__ == '__main__':
main()
File Structure below:
calendar_app/
├── path/
├── .env
├── .gitignore
├── README.md
├── requirements.txt
├── schedule.py
└── token.json # auto-generated after OAuth login