generated from ajparsons/python-poetry-auto-template
-
Notifications
You must be signed in to change notification settings - Fork 0
57 lines (47 loc) · 1.71 KB
/
send_update_democracy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
name: Update democracy subscribers
on:
workflow_dispatch:
schedule:
# run every weekday as 7
- cron: "0 7 * * 1-5"
jobs:
send:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# setup python 3.10
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: false
- name: Setup
run: |
pip install j2cli
poetry install
- uses: DamianReeves/write-file-action@v1.2
with:
path: template.md.j2
contents: |
{% for item in segments %}
{{ item.name.replace("Interest: ", "") }}: {{ "{:,}".format(item.member_count) }} (last seven days: {{ item.recent_email_count }}) {% endfor %}
- name: Get data
run: |
python -m mysoc_mailchimp segments --pattern "Interest: Demo" --include-recent-count --order-by member_count --desc --json > data.json
# join the two files
# generate the message
j2 --format=json template.md.j2 data.json > formatted_message.md
# take this message and put it into a json file under the key 'message'
jq -n --arg message "$(cat formatted_message.md)" '{"message": $message}' > payload-slack-content.json
env:
MAILCHIMP_API_KEY: ${{ secrets.MAILCHIMP_API_KEY }}
- name: Send custom JSON data to Slack workflow
id: slack
uses: slackapi/slack-github-action@v1.23.0
with:
payload-file-path: "./payload-slack-content.json"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DEMOCRACY_WEBHOOK_URL }}