Skip to content
PashovskiPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Food Co-op Shift Auto-Claimer 🛒

The Park Slope Food Co-op is a member-run grocery store in Brooklyn, NY where every member is required to work a shift roughly once a month in exchange for the right to shop. Open shifts that get released back to the pool (when someone cancels, swaps, or a new cycle opens) are claimed on a first-come, first-served basis and tend to disappear within seconds. This script logs into the members site, watches the shift calendar across the next several weeks, and auto-claims an open shift the moment one appears, using a configurable priority list so you get the time slot and role you actually want.

Features

  • Multi-week monitoring: Simultaneously monitors shifts across 6 weeks
  • Smart priority system: Claims shifts based on your preferred times and roles
  • Auto-claim with limits: Respects co-op shift limits (default: 2 shifts max)
  • Already-claimed detection: Skips shifts you've already claimed (green checkmark)
  • Retry mechanism: Attempts to reclaim shifts if they become available again
  • Multi-channel notifications:
    • Windows sound alerts
    • Pushbullet notifications
    • Alexa voice announcements via Home Assistant

Prerequisites

  • Python 3.x
  • Chrome browser
  • Chrome WebDriver
  • Home Assistant instance (optional, for notifications)
  • Pushbullet account (optional)
  • Alexa devices with Home Assistant integration (optional)

Installation

  1. Clone this repository:
git clone [your-repo-url]
cd auto_refresh
  1. Install required packages:
pip install selenium requests
  1. Download Chrome WebDriver:
    • Download from ChromeDriver
    • You'll point the script at these paths via environment variables (see Setup below)

Setup

All secrets and machine-specific paths are read from environment variables. Nothing is hardcoded in the script. Copy .env.example to .env (or export the variables in your shell however you prefer) and fill in real values. The script does not load .env automatically; either export the variables in your shell session before running, or use a tool of your choice to load them.

The following environment variables are required (the script will raise KeyError on startup if any are missing):

Variable Description
CHROME_BINARY Absolute path to your Chrome (or Chrome for Testing) executable.
CHROME_USER_DATA_DIR Absolute path to the Chrome user-data directory containing the profile you're logged into the co-op with.
CHROMEDRIVER_PATH Absolute path to the matching chromedriver executable.
YOUR_INITIALS Your member initials, as entered on the co-op claim form (e.g. PD).
HA_URL Base URL of your Home Assistant instance (e.g. http://192.168.1.10:8123).
HA_TOKEN A Home Assistant long-lived access token. See Home Assistant docs for how to create one.
HA_NOTIFY_SERVICE The notify service to use (e.g. notify.pushbullet).

See .env.example in the repo root for a template with placeholder values.

If you don't use Home Assistant, set ENABLE_HA_NOTIFICATIONS = False near the top of auto_claim.py. The HA env vars must still be defined (use any placeholder values).

Configuration

Edit the configuration section in auto_claim.py:

Basic Settings

AUTO_CLAIM = True  # Set to False for notification-only mode
CREDIT_TO_SELF = True  # True = credit yourself, False = credit housemate
MAX_SHIFTS = 2  # Maximum shifts to claim (co-op limit)
WEEKS_TO_MONITOR = 6  # Number of weeks to monitor (1-6)

YOUR_INITIALS is set via the environment variable of the same name (see Setup).

Shift Priorities

Define your preferred shifts in order of priority:

SHIFT_PRIORITIES = [
    {"time": "10:30am", "role": None},  # Any 10:30am shift
    {"time": "1:00pm", "role": None},   # Any 1:00pm shift
    {"time": None, "role": "Cart Return"},  # Any Cart Return shift
    {"time": None, "role": None},  # Any other shift
]

Chrome Configuration

Chrome and ChromeDriver paths are set via the CHROME_BINARY, CHROME_USER_DATA_DIR, and CHROMEDRIVER_PATH environment variables (see the Setup section above).

Home Assistant Integration (Optional)

HA_URL, HA_TOKEN, and HA_NOTIFY_SERVICE are configured via environment variables (see the Setup section above). To toggle notifications on or off, edit the ENABLE_HA_NOTIFICATIONS flag near the top of auto_claim.py.

To get a Home Assistant token:

  1. Go to your HA profile (click username in bottom left)
  2. Scroll to "Long-Lived Access Tokens"
  3. Create a new token and copy it into your .env

Usage

  1. Run the script:
python auto_claim.py
  1. If not already logged in, the script will wait for you to log into the food co-op website

  2. The script will:

    • Open tabs for each week you're monitoring
    • Check for available shifts every 3 seconds
    • Notify you when shifts become available
    • Auto-claim shifts matching your priorities (if enabled)
    • Send notifications to all configured channels
  3. Press Ctrl+C to stop monitoring

How It Works

  1. Shift Detection: Searches for <a class="shift"> elements on each page
  2. Claimed Detection: Skips shifts with my_shift class (your claimed shifts with ✅)
  3. Priority Matching: Claims shifts in order of your defined priorities
  4. Failure Handling: Retries failed claims up to 3 times
  5. Notification System: Sends alerts via multiple channels when shifts are claimed

Troubleshooting

Script can't find Chrome/ChromeDriver

  • Verify the paths in the configuration match your installation
  • Ensure Chrome and ChromeDriver versions are compatible

Notifications not working

  • Check your Home Assistant token is valid
  • Verify Home Assistant is accessible at the configured URL
  • Ensure Pushbullet and Alexa integrations are set up in HA

Script tries to claim already-claimed shifts

  • The script now detects the green checkmark (✅) on claimed shifts
  • If issues persist, check that the my_shift class detection is working

Can't claim shifts after release

  • The script tracks failed attempts and will retry up to 3 times
  • Shifts are removed from the "seen" list after release

Safety Features

  • Respects co-op shift limits
  • Won't claim more than MAX_SHIFTS
  • Handles alerts and confirmations automatically
  • Graceful error handling with retry logic
  • Network failure resilience for notifications

Disclaimer

This tool is for personal use. Please respect your co-op's policies regarding shift claiming and automation. The authors are not responsible for any issues arising from the use of this script.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages