Skip to content

Commit

Permalink
Allow multiple public sections per meeting day
Browse files Browse the repository at this point in the history
  • Loading branch information
mb committed Jan 23, 2024
1 parent 3f95321 commit c727f00
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 44 deletions.
74 changes: 74 additions & 0 deletions extract
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env python3

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

# Author: Manuel Bucher <[email protected]>
# Date: 2024-01-23

import sys
import re
import datetime

# <p><strong>[2024-01-09] 2024 Edition! </strong></p></td>



def main():
try:
_, inp = sys.argv
except:
print(f"usage: {sys.argv[0]} INPUT.md")
return
date = ""
extract = False
last_out = ""
out = {}
for line in open(inp):
public = '--- public ---' in line
private = '--- private ---' in line
if not extract:
if public and private:
continue
if public:
extract = True
continue
if private:
print("non-matching private tag")
return 1

# look for next section
if '[' in line:
new_date = line.split('[', 1)[1]
new_date = new_date.split(']', 1)[0]
try:
new_date = datetime.datetime.strptime(new_date, '%Y-%m-%d')
except ValueError:
continue
date = new_date.strftime("%Y-%m-%d")
last_out = last_out.strip()
if last_out != "":
out[date] = last_out + "\n"
last_out = ""
print(date)
else:
if public and private:
print("public and private tag in public section")
return 1
elif public:
print("public tag in public section")
return 1
elif private:
extract = False
else:
last_out += line

# write all meeting notes to files
for day in out:
with open(f"archive/meeting-{day}.md", "w") as f:
f.write(out[day])

if __name__ == '__main__':
sys.exit(main())

47 changes: 3 additions & 44 deletions update
Original file line number Diff line number Diff line change
Expand Up @@ -19,69 +19,28 @@

set -euxo pipefail

DATE="$(date +"%Y-%m-%d")"

if [ $# -ne 0 ]; then
if [[ $1 == -* ]]; then
echo "Usage $0 [meeting-note-date]"
echo "If no meeting-note-date is provided, the current date ($DATE) is used"
exit 1
fi
DATE="$1"
fi

OUTPUT_FILE="archive/meeting-${DATE}.md"

current_date=$(date +"%Y-%m-%d %H:%M:%S")
echo "Current Date: $current_date"

# Use last downloaded file for meeting notes. If there is a newer file use `touch` on the
# meeting notes to convert
DOWNLOAD_DIR="$HOME/Downloads"
INPUT_FILE="$DOWNLOAD_DIR/$(ls -Art $DOWNLOAD_DIR | tail -n 1)"

# Remember whether the output file currently exist to create a meaningful commit message
# for updates https://stackoverflow.com/a/24896746
UPDATE=0
[ -f "${OUTPUT_FILE}" ] || UPDATE=$?

# Convert to markdown
pandoc --wrap=none -t commonmark_x -i "${INPUT_FILE}" -o "meeting-notes.0.md"

# extract part between "--- public ---" and "--- private ---"
START="--- *public *---"
END="--- *private *---"
sed -n "/${START}/,/${END}/p" "meeting-notes.0.md" > meeting-notes.1.md

# check whether the closing tag is missing, exit to prevent leaking information
# Either by having only a start, but no end. Or by reaching the next start/end tag
if [[ $(grep -- "${START}" meeting-notes.1.md | wc -l) -ne 1 ]]
then
echo "End mark missing, make sure the ${START} has a matching ${END}"
exit 1
fi

# remove first and last line https://stackoverflow.com/a/10460956
tail -n +2 meeting-notes.1.md | head -n -1 > meeting-notes.2.md

cp meeting-notes.2.md "${OUTPUT_FILE}"
./extract meeting-notes.0.md

# Regenerate index of meeting notes
./summary > archive/SUMMARY.md

# Add new files for next commit
git add $OUTPUT_FILE
git add archive/SUMMARY.md
git add archive/

# Show diff to commit for review
git diff --staged --color=always | less -R

# Write commit message, but ask for confirmation
if [ -n "${UPDATE}" ]; then
git commit -m "Update meeting notes from ${DATE}" -e
else
git commit -m "Add meeting notes from ${DATE}" -e
fi
git commit -m "Add meeting notes" -e

# show the commit for last review before pushing
git --no-pager show HEAD
Expand Down

0 comments on commit c727f00

Please sign in to comment.