Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/monthly-agenda.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
workflow_dispatch:
schedule:
- cron: '0 0 1 * *'

jobs:
setup:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v2
with:
python-version: '3.x'
- run: pip install -r requirements.txt
build:
needs: setup
runs-on: ubuntu-latest
steps:
- run: ./new_agenda.py
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
*swp
*~
.DS_Store
venv
config.json
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,17 @@
# Administrative Documents
Administrative resources for the org

# How to use this repository
This repository includes some automation to handle monthly agenda tasks. The
automation is handled by a GitHub Action that runs on the first of every month.

## Setup
cp config-template.json config.json
vi config.json
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

## Running the automation
It magically works on the first of every month.

6 changes: 6 additions & 0 deletions config-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"__comment": "This is a template for the config.json file. Fill in the values and rename the file to config.json",
"telegram_bot_token": "YOUR_TELEGRAM_BOT_TOKEN",
"telegram_chat_id": "YOUR_TELEGRAM_CHAT_ID",
"github_repo_base_url": "https://github.com/PawprintPrototyping/admin"
}
59 changes: 59 additions & 0 deletions new_agenda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
This script is used to create a new agenda for the last Tuesday of next month.
"""
import os
import sys
import json
import datetime
import requests

# Load the configuration from config.json
with open('config.json', encoding='utf-8') as f:
config = json.load(f, encoding='utf-8')

if 'telegram_bot_token' not in config or 'telegram_chat_id' not in config:
print('Missing entries in config.json!')
sys.exit(1)

for meetings in ['general', 'board']:
for doctypes in ['agendas', 'minutes']:
# Check to make sure the directories exist
if not os.path.exists(f'./{meetings}/{doctypes}'):
print(f'Expected directory {meetings}/{doctypes} does not exist!')
sys.exit(1)

today = datetime.date.today()
next_month = today.replace(day=1) + datetime.timedelta(days=32)
last_tuesday = next_month.replace(day=1) - datetime.timedelta(days=1)
while last_tuesday.weekday() != 1:
last_tuesday -= datetime.timedelta(days=1)
print(f'Last Tuesday of the month is {last_tuesday}')

# Get the most recent agenda by ctime
agendas = os.listdir(f'./{meetings}/agendas')
agendas.sort(key=lambda x, m=meetings: os.path.getctime(f'./{m}/agendas/{x}'))
most_recent = agendas[-1]

print(f'Most recent agenda is {most_recent}')
if not os.path.exists(f'./{meetings}/agendas/{last_tuesday}'):
# Copy the most recent agenda to a new agenda for the last Tuesday
#os.system(f'cp ./{meetings}/agendas/{most_recent} ./{meetings}/agendas/agenda_{last_tuesday}.md')
print(f'Copied {most_recent} to agenda_{last_tuesday}.md')
# Commit the new agenda
os.system(f'git add ./{meetings}/agendas/agenda_{last_tuesday}.md')
os.system(f'git commit -m "Add agenda for {last_tuesday}"')
os.system('git push origin master')
# Tell everyone on telegram
print(f'Notifying telegram chat {config.telegram_chat_id}')
result = requests.post(f'https://api.telegram.org/bot{config.telegram_bot_token}/sendMessage', data={
'chat_id': config.telegram_chat_id,
'text': f'New {meetings} agenda for {last_tuesday} is available at {config.github_repo_base_url}/tree/master/{meetings}/agendas/agenda_{last_tuesday}.md'
})
if result.status_code != 200:
print(f'Failed to notify telegram chat {config.telegram_chat_id}')
else:
print('Notified telegram chat successfully:')
print(result.text)
else:
print(f'Agenda for {last_tuesday} already exists, exiting')
sys.exit(0)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests