Package: safeway-coupons
Automatic Safeway coupon clippersafeway-couponsis a script that will log in to an account on safeway.com,
and attempt to select all of the "Safeway for U" electronic coupons on the site
so they don't have to each be clicked manually.Design notesSafeway's sign in page is protected by a web application firewall (WAF).
safeway-coupons performs authentication using a headless instance of Google
Chrome. Authentication may fail based on your IP's reputation, either by
presenting a CAPTCHA or denying sign in attempts altogether. safeway-coupons
currently does not have support for prompting the user to solve CAPTCHAs.Once a signed in session is established, coupon clipping is performed using HTTP
requests viarequests.Installation and usage with DockerA Docker container is provided which runs safeway-coupons with cron. The cron
schedule and your Safeway account details may be configured using environment
variables, or with an accounts file.Exampledocker-compose.yamlwith configuration via environment variables:version:"3.7"services:safeway-coupons:image:ghcr.io/smkent/safeway-coupons:latestenvironment:CRON_SCHEDULE:"02***"# Run at 2:00 AM UTC each day# TZ: Antarctica/McMurdo  # Optional time zone to use instead of UTCSMTPHOST:your.smtp.hostSAFEWAY_ACCOUNT_USERNAME:your.safeway.account.email@example.comSAFEWAY_ACCOUNT_PASSWORD:very_secretSAFEWAY_ACCOUNT_MAIL_FROM:your.email@example.comSAFEWAY_ACCOUNT_MAIL_TO:your.email@example.com# EXTRA_ARGS: --debug  # Optionalrestart:unless-stoppedExampledocker-compose.yamlwith configuration via accounts file:version:"3.7"services:safeway-coupons:image:ghcr.io/smkent/safeway-coupons:latestenvironment:CRON_SCHEDULE:"02***"# Run at 2:00 AM UTC each day# TZ: Antarctica/McMurdo  # Optional time zone to use instead of UTCSMTPHOST:your.smtp.hostSAFEWAY_ACCOUNTS_FILE:/accounts_file# EXTRA_ARGS: --debug  # Optionalrestart:unless-stoppedvolumes:-path/to/safeway_accounts_file:/accounts_file:roStart the container by running:docker-compose up -dDebugging information can be viewed in the container log:docker-compose logs -fInstallation from PyPIPrerequisitesGoogle Chrome (for authentication performed via Selenium).Optional:sendmail(for email support)Installationsafeway-coupons is available on PyPI:pip install safeway-couponsUsageFor best results, run this program once a day or so with a cron daemon.For full usage options, runsafeway-coupons --helpConfigurationsafeway-couponscan clip coupons for one or more Safeway accounts in a
single run, depending on the configuration method used.If a sender email address is configured, a summary email will be sent for each
Safeway account viasendmail. The email recipient defaults to the Safeway
account email address, but can be overridden for each account.Accounts are searched via the following methods in the listed order. Only one
account configuration method may be used at a time.With environment variablesA single Safeway account can be configured with environment variables:SAFEWAY_ACCOUNT_USERNAME: Account email address (required)SAFEWAY_ACCOUNT_PASSWORD: Account password (required)SAFEWAY_ACCOUNT_MAIL_FROM: Sender address for email summarySAFEWAY_ACCOUNT_MAIL_TO: Recipient address for email summaryWith config fileMultiple Safeway accounts can be provided in an ini-style config file, with a
section for each account. For example:email_sender=sender@example.com; optional[safeway.account@example.com]       ; requiredpassword=12345; requirednotify=your.email@example.com; optionalProvide the path to your config file using the-cor--accounts-configoption:safeway-coupons -c path/to/config/fileDevelopmentPoetryinstallationViapipx:pip install pipxpipx install poetrypipx inject poetry poetry-dynamic-versioning poetry-pre-commit-pluginViapip:pip install poetrypoetry self add poetry-dynamic-versioning poetry-pre-commit-pluginInvocation with docker-composesafeway-coupons can be executed within a Docker container usingdocker-compose.dev.yaml.To use, first create anaccountsfile in the same directory with your
safeway-coupons accounts configuration. Then, execute safeway-coupons within a
container using docker-compose:docker-compose -f docker-compose.dev.yaml up --buildThe container will run safeway-coupons once, attempt to clip one coupon, and
then stop.To change the safeway-coupons arguments, modify thecommandvalue indocker-compose.dev.yaml.When finished with development tasks, the docker-compose state can be cleaned up
with:docker-compose -f docker-compose.dev.yaml downDevelopment tasksSetup:poetry installRun static checks:poetry run poe lintorpoetry run pre-commit run --all-filesRun static checks and tests:poetry run poe testCreated fromsmkent/cookie-pythonusingcookiecutter