Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

consoledotdev/lamsubs-py

Repository files navigation

Mailchimp App for LaMetric (Python)

An HTTP endpoint for polling Mailchimp subscriber numbers for an LaMetric Time device. Designed to run on Azure Functions as an HTTP endpoint.

Methods

Deployment

Uses main.bicep to define the Azure resources.

Automatic

Uses Azure ARM and Login GitHub actions to deploy.

AZURE_CREDENTIALS created as per the service principal instructions:

az ad sp create-for-rbac --name "lamsubs-py - GitHub" --sdk-auth --role contributor \
    --scopes /subscriptions/244fa449-6833-417a-9b8e-be5a66bdf344/resourceGroups/lamsubs-py

AZURE_FUNCTIONAPP_PUBLISH_PROFILE set up according to the docs.

Manual

Install Bicep which is used to compile the ARM template that manages the Azure resources.

# Assumes bc-totorobot-py resource group exists
bicep build ./main.bicep # generates main.json
az login
az deployment group create -f ./main.json -g lamsubs-py
func azure functionapp publish lamsubs-py

Local development

Setup

Install the Azure Functions SDK and Azure CLI, then:

  1. python3 -m venv .venv
  2. source .venv/bin/activate
  3. pip3 install -r requirements.txt

Local dev server

# Set these values appropriately
export MAILCHIMP_API_KEY=""
export MAILCHIMP_LIST_ID=""
func host start

Trigger timer function

curl -i http://localhost:7071/api/getConfirmedSubscribers

Tests

python3 -m pytest

Coverage reports:

python3 -m coverage run -m pytest
python3 -m coverage report --omit '.venv/*'

Environment variables

These are substituted in as part of the deploy process and set in the GitHub repo secrets:

  • AZURE_CREDENTIALS discussed above.
  • AZURE_FUNCTIONAPP_PUBLISH_PROFILE discussed above.
  • MAILCHIMP_API_KEY from Mailchimp settings to be able to connect to the API. MAILCHIMP_LIST_ID from Audience settings.