1# Scripting Patterns
2
3Automation examples using exo-teams.
4
5## Fetch all assignments and check status
6
7```bash
8#!/bin/bash
9echo "=== PENDING DEADLINES ==="
10exo-teams deadlines
11
12echo ""
13echo "=== ALL ASSIGNMENTS ==="
14exo-teams assignments
15```
16
17```bash
18# Machine-readable pipeline
19exo-teams assignments --json | jq '
20 .[] | {
21 class: .className,
22 name: .displayName,
23 due: .dueDateTime,
24 status: .submissionStatus
25 }
26'
27```
28
29## Download all class materials
30
31```bash
32#!/bin/bash
33TEAM="Academic Writing"
34OUTPUT_DIR="./class-materials"
35mkdir -p "$OUTPUT_DIR"
36
37# List files
38exo-teams files "$TEAM" --drive "Class Materials" --json | jq -r '.[] | select(.folder == null) | .name' | while read name; do
39 exo-teams download "$TEAM" \
40 --path "Class Materials/$name" \
41 --drive "Class Materials" \
42 --output "$OUTPUT_DIR/$name"
43done
44```
45
46## Send a file to someone
47
48```bash
49# Step 1: find their chat ID
50exo-teams list-chats | grep "Alice"
51# * [DM ] Alice Smith 19:abc123@unq.gbl.spaces
52
53# Step 2: send
54exo-teams send-file "19:abc123@unq.gbl.spaces" \
55 --file report.pdf \
56 --message "Here's the report"
57```
58
59## Submit an assignment
60
61```bash
62# Check what's pending
63exo-teams deadlines
64
65# Submit
66exo-teams submit "Academic Writing" "Essay 1" --file my-essay.docx
67```
68
69## Monitor a channel for new messages (poll loop)
70
71```bash
72#!/bin/bash
73CHANNEL="General"
74LAST_DATE=$(date -u +"%Y-%m-%d")
75
76while true; do
77 echo "--- checking at $(date) ---"
78 exo-teams get-messages "$CHANNEL" --since "$LAST_DATE"
79 LAST_DATE=$(date -u +"%Y-%m-%d")
80 sleep 60
81done
82```
83
84## Export a conversation to markdown
85
86```bash
87#!/bin/bash
88CHAT="Alice"
89OUTPUT="chat-export.md"
90
91echo "# Chat Export: $CHAT" > "$OUTPUT"
92echo "Generated: $(date)" >> "$OUTPUT"
93echo "" >> "$OUTPUT"
94
95exo-teams get-chat "$CHAT" --all --json | jq -r '
96 reverse[] |
97 select(.messagetype == "RichText/Html" or .messagetype == "Text") |
98 "**[\(.composetime | split("T")[0])] \(.imdisplayname):** \(.content | gsub("<[^>]*>"; ""))"
99' >> "$OUTPUT"
100
101echo "Exported to $OUTPUT"
102```
103
104## Check all unread and mark them
105
106```bash
107# See unread
108exo-teams unread --json | jq -r '.[].id'
109
110# Mark all unread as read
111exo-teams unread --json | jq -r '.[].id' | while read id; do
112 echo "marking $id as read..."
113 exo-teams mark-read "$id"
114done
115```
116
117## Bulk search and find files
118
119```bash
120# Search for files matching a query
121exo-teams search "lecture notes" --json | jq '
122 .[] |
123 select(.resource.name != null) |
124 {name: .resource.name, url: .resource.webUrl}
125'
126```
127
128## Get today's calendar and assignments together
129
130```bash
131echo "=== CALENDAR TODAY ==="
132exo-teams calendar --days 1
133
134echo ""
135echo "=== DUE SOON ==="
136exo-teams deadlines | head -5
137```
138
139## Tips
140
141- All commands accept `--json` - pipe into `jq` for filtering/transformation
142- `get-messages` and `get-chat` print status to stderr, data to stdout - safe to redirect stdout
143- `--all` flag on get-messages follows backwardLink pagination automatically
144- `--since` accepts `YYYY-MM-DD` or `YYYY-MM-DD HH:MM:SS`
145- Token refresh is automatic - no need to manually call `auth --refresh` in scripts