Skip to content

Instantly share code, notes, and snippets.

@leucos
Last active February 16, 2020 14:15
Show Gist options
  • Save leucos/749a766092471def596f334175a5fdac to your computer and use it in GitHub Desktop.
Save leucos/749a766092471def596f334175a5fdac to your computer and use it in GitHub Desktop.
Send Twilio SMS on non-Blue EDF tempo days
#!/bin/bash
# This snippet will send a SMS when next EDF Tempo day is not Blue
# Better run this around noon
# https://particulier.edf.fr/fr/accueil/contrat-et-conso/options/tempo.html#/selection-bp
RTE_AUTH="xyz" # sbase64 auth token; ee https://data.rte-france.com/ for an account; then create an "App" for "Tempo Like Supply Contract"
TWILIO_ACCOUNT_ID="someid" # see https://www.twilio.com/console
TWILIO_AUTH_TOKEN="sometoken" # see https://www.twilio.com/console
FROM_PHONE="+33999999" # phon# to send from, see https://www.twilio.com/console
# List of phones to warn
PHONES="+33123456 +15467897"
# Get rolling
TOKEN=$(curl -sXPOST https://digital.iservices.rte-france.com/token/oauth/ -H "Authorization: Basic ${RTE_AUTH}" | jq -r '.["access_token"]')
COLOR=$(curl -sH"Authorization: Bearer $TOKEN" "https://digital.iservices.rte-france.com/open_api/tempo_like_supply_contract/v1/tempo_like_calendars" | jq -r '.["tempo_like_calendars"]["values"][0]["value"]')
if [ "x$COLOR" != "XBLUE" ]; then
for phone in $PHONES; do
curl -sX POST https://api.twilio.com/2010-04-01/Accounts/${TWILIO_ACCOUNT_ID}/Messages.json \
--data-urlencode "Body=Demain jour $COLOR" \
--data-urlencode "From=${FROM_PHONE}" \
--data-urlencode "To=${phone}" \
-u ${TWILIO_ACCOUNT_ID}:${TWILIO_AUTH_TOKEN} -o /dev/null
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment