A CLI tool to check your availability across Google Calendar and Outlook calendars.
-
Clone this repository:
git clone https://github.com/yourusername/availability-checker.git cd availability-checker -
Install the required packages:
pip install -r requirements.txt -
Set up API credentials:
- Go to the Google Cloud Console
- Create a new project
- Enable the Google Calendar API
- Create OAuth 2.0 credentials (Desktop application)
- Download the credentials JSON file
- Save it to
~/.config/avail/google_credentials.json
- Go to the Microsoft Azure Portal
- Register a new application
- Add the Calendar.Read API permission
- Get the client ID and client secret
- Create a file at
~/.config/avail/outlook_credentials.jsonwith the following format:{ "client_id": "YOUR_CLIENT_ID", "client_secret": "YOUR_CLIENT_SECRET" }
-
Make the script executable:
chmod +x avail.py -
(Optional) Create a symlink to use it from anywhere:
sudo ln -s $(pwd)/avail.py /usr/local/bin/avail
avail [DAYS] [OPTIONS]
DAYS: Number of days to look ahead for availability (default: 3 days if not specified)
-p, --professional: Limit to professional hours (9AM-5PM, no weekends)-pst, --pst: Use PST timezone for this query-est, --est: Use EST timezone for this query-default, --set-default-timezone [EST|PST]: Set default timezone for future use-q, --quiet: Toggle quiet mode on/off (error messages are suppressed by default)-toggle, --toggle-timezone: Toggle between EST and PST as default timezone--google/--no-google: Enable/disable Google Calendar integration--outlook/--no-outlook: Enable/disable Outlook Calendar integration--cache/--no-cache: Enable/disable caching of API responses--cache-time [SECONDS]: Set cache expiration time in seconds--clear-cache: Clear all cached API responses
Check availability for the next 3 days (default):
avail
Check availability for the next 5 days:
avail 5
Toggle quiet mode on/off:
avail -q
Toggle default timezone between EST and PST:
avail -toggle
Disable Outlook Calendar integration:
avail --no-outlook
Enable only Google Calendar integration:
avail --no-outlook -google
Enable response caching (already on by default):
avail --cache
Set cache expiration to 10 minutes (600 seconds):
avail --cache-time 600
Clear all cached responses:
avail --clear-cache
Check professional availability (9AM-5PM, no weekends) for the next week:
avail 7 -p
Check availability in PST timezone:
avail -pst
Check availability in EST timezone:
avail -est
Set PST as your default timezone:
avail --set-default-timezone PST
The tool allows you to set a default timezone (EST or PST) to match your current location:
- If you're in San Francisco:
avail -toggleoravail --set-default-timezone PST - If you're in New York:
avail -toggleoravail --set-default-timezone EST
You can always override the default for a specific query with the -est or -pst flags.
The tool displays available time slots in different formats based on the date range:
Mo - 3:00 PM - 5:00 PM
Tu - 10:00 AM - 11:00 AM // 2:30 PM - 4:00 PM
Mo 15th - 3:00 PM - 5:00 PM
Tu 16th - 10:00 AM - 11:00 AM // 2:30 PM - 4:00 PM
January 15 Mo - 3:00 PM - 5:00 PM
February 1 Tu - 10:00 AM - 11:00 AM // 2:30 PM - 4:00 PM
Where:
- The day is represented by the first two letters (Mo, Tu, We, etc.)
- Multiple time slots for the same day are separated by double slashes (
//) - The output is automatically copied to your clipboard for easy sharing
The tool uses a configuration system stored in JSON format at ~/.config/avail/config.json. This stores:
default_timezone: The default timezone to use (EST or PST)quiet_mode: Whether to suppress error messages and notifications (default: true)
Configuration is loaded at startup and persists between runs. The -toggle and -q flags modify this configuration file.
API credentials and tokens are stored in the ~/.config/avail/ directory:
google_credentials.json: Your Google API credentialsgoogle_token.pickle: Cached Google authentication tokenoutlook_credentials.json: Your Microsoft API credentialsoutlook_token.pickle: Cached Microsoft authentication token
The tool integrates with two calendar systems:
-
Google Calendar API:
- Uses OAuth2 authentication
- Fetches all calendars associated with your Google account
- Reads events from each calendar within the specified date range
-
Microsoft Outlook/Office 365 API:
- Uses OAuth2 authentication
- Accesses your default Office 365 calendar
- Reads events including recurring events
The availability checker works as follows:
-
Fetch Busy Slots:
- Retrieves events from Google Calendar
- Retrieves events from Outlook Calendar
- Combines all events into a unified list of "busy" time slots
-
Merge Overlapping Slots:
- Sorts all busy slots by start time
- Merges any overlapping busy periods to avoid duplicates
-
Generate Available Slots:
- Creates a list of all possible time slots in 15-minute intervals
- For professional mode, limits to 9AM-5PM and excludes weekends
- Removes any slots that overlap with busy periods
- Merges adjacent available slots into continuous blocks
-
Format Output:
- Groups available slots by day
- Formats dates based on the range (< 7 days, same month, cross-month)
- Adds ordinal suffixes (1st, 2nd, 3rd) for dates when appropriate
The tool uses a 15-minute time block interval for slot calculations. This can be modified by changing the TIME_BLOCK_INTERVAL constant in the code.
Results are automatically copied to the clipboard using the pyperclip library, allowing you to easily paste your availability into emails or messages.
The tool has comprehensive error handling for:
- Missing credential files
- API authentication failures
- Event retrieval failures
- Timezone conversion issues
In quiet mode (default), these errors are suppressed to provide clean output.
The tool is optimized for performance in several ways:
-
Asynchronous API Calls:
- Calendar API requests run in parallel using async/await
- Multiple calendars are fetched concurrently
- Google and Outlook calendars are queried simultaneously
-
Response Caching:
- API responses are cached locally (enabled by default)
- Default cache expiration is 5 minutes (configurable)
- Cached responses bypass network requests entirely
- Cache can be cleared manually with
--clear-cache
-
Calendar Service Selection:
- Selectively enable only the calendar services you use
- Each disabled service provides significant performance gains
-
Lazy Loading:
- Calendar services are only initialized when actually needed
- Service clients are instantiated only when first accessed
-
Error Recovery:
- Better error handling with less waiting for timeouts
- Graceful fallback when API services are unavailable
For optimal performance:
# Enable caching with a longer timeout (15 minutes)
avail --cache --cache-time 900
# Use only the calendar service you primarily use
avail --no-outlook # If you mainly use Google Calendar
avail --no-google # If you mainly use Outlook
# Clear cache if you need fresh data
avail --clear-cache
These optimizations can reduce execution time by up to 80% compared to the original implementation, especially when using caching and disabling unused calendar services.
On the first run, you'll be prompted to authorize the application to access your calendars:
- For Google Calendar, a browser window will open asking you to sign in and grant permissions
- For Outlook, you'll be prompted to sign in via a browser window
After successful authentication, tokens will be saved locally so you won't need to authenticate again unless the tokens expire.
If you've installed this tool using pyenv, you can set up an alias in your ~/.zshrc file:
alias avail="~/.pyenv/versions/availability-checker/bin/avail"
After adding the alias, remember to run source ~/.zshrc or restart your terminal to apply the changes.