diff --git a/.github/workflows/monthly-agenda.yaml b/.github/workflows/monthly-agenda.yaml new file mode 100644 index 0000000..2f93144 --- /dev/null +++ b/.github/workflows/monthly-agenda.yaml @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5b6f6f6..dafb2ac 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *swp *~ .DS_Store +venv +config.json diff --git a/README.md b/README.md index c29f15d..6a79d43 100644 --- a/README.md +++ b/README.md @@ -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. + diff --git a/config-template.json b/config-template.json new file mode 100644 index 0000000..e76eac1 --- /dev/null +++ b/config-template.json @@ -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" +} diff --git a/new_agenda.py b/new_agenda.py new file mode 100755 index 0000000..b431b33 --- /dev/null +++ b/new_agenda.py @@ -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) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f229360 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +requests