Skip to content

Instantly share code, notes, and snippets.

View phette23's full-sized avatar
🌹
"you're right, no human being would stack books like this"

Eric Phetteplace phette23

🌹
"you're right, no human being would stack books like this"
View GitHub Profile
@phette23
phette23 / readme.md
Created January 17, 2025 21:03
Scrape Moodle courses data from module list search

Scrape Moodle Module List

On the Manage Activities admin page there's a count of how many courses use a particular activity and you can click the count to execute a search that retrieves all those courses. There's a button to show all the courses on the same page, but no useful way to do further filtering or extract data. The JS above can be copy-pasted into your browser's JavaScript console to create a CSV of the courses listed on the module list page.

We have parentheticals for semester in our course titles like "20th Century Fashion (2022SP)" so this attempts to extract those, though the regex is primitive and will mess up with courses with a second set of parentheses. This is usually easy to cleanup manually.

@phette23
phette23 / moodle-filedir-csv.sh
Created July 16, 2024 19:20
create CSV of file paths, size, and last accessed times for Moodle filedir
#!/usr/bin/env bash
# create a csv of path, file size, last access time for all files in a directory tree
# usage: file-tree-csv.sh /path/to/directory > output.csv
FILEDIR=/opt/moodledata/filedir
cd $FILEDIR || (echo "Moodle filedir not found, exiting" && exit 1)
echo "path,size,atime"
# shellcheck disable=SC2044
# all Moodle file names & paths only contain hexadecimal chars
for file in $(find . -type f); do
size=$(stat -c %s $file)
@phette23
phette23 / missing-names.py
Created June 27, 2024 18:47
find mods/subject/name values in our metadata but not in our names taxonomy
#!/usr/bin/env python
# run from root of cca/vault_migration project over _all_ VAULT metadata JSON like
# `poetry run python missing-names.py vm/*.json`
import csv
import json
import os
import sys
import xmltodict
@phette23
phette23 / backup-db-table.sh
Last active December 14, 2023 21:54
retroactively add db entries to group
# backup the mdl_data_records table before we modify it
gcloud sql export sql mysql-prod-1 gs://cca-manual-db-dumps/(dt)-mdl_data_records.sql -d m_prod1 -t mdl_data_records
@phette23
phette23 / download.fish
Created October 27, 2023 23:01
download all VAULT items
#!/usr/bin/env fish
# download ALL live vault items to item.json and metadata.xml files
# 47283 total items, we can download 50 at a time
set total (eq search -l 1 | jq '.available')
set length 50
set pages (math floor $total / $length)
for i in (seq 0 $pages)
set start (math $i \* $length)
echo "Downloading items $start to" (math $start + $length)
eq search -l $length --info metadata --start $start > .tmp/$i.json
@phette23
phette23 / syllabi-section-check.js
Created October 20, 2023 15:54
check if sections syllabi are on VAULT search results page
// check if these sections appear on EQUELLA search results page
const sections = [
'GELCT-6700-2',
'LITPA-2000-10',
'WRITE-6000-2',
]
console.log(`Checking for ${sections.length} section codes`)
// return list of missing sections
const missing = sections.filter(s => {
@phette23
phette23 / warc-download.sh
Created October 20, 2023 15:40
download Archive-It WARCs to backup
#!/usr/bin/env fish
# used for Art Practical site
# fill in credentials
set USER username
set PASS password
set COLLECTION 15633
# destination files
set JSONFILE data.json
@phette23
phette23 / crcheckall.js
Created March 1, 2023 18:56
select all checkboxs on chrome's history page chrome://history
document
.querySelector('history-app').shadowRoot
.querySelector('history-list').shadowRoot
.querySelectorAll('history-item').forEach((hi, i) => {
const cbox = hi.shadowRoot.querySelector('cr-checkbox')
// merely setting checked = true doesn't work, chrome wants you to click them
if (!cbox.checked) cbox.click()
})
@phette23
phette23 / homebrew bump.md
Created December 1, 2022 17:34
bumping a homebrew formula version in brief

The How to Open a Homebrew Pull Request documentation is great. This doc assumes you've already created a fork of homebrew-core named after your user and a branch tracking the master of the fork.

cd (brew --repository homebrew/core)
brew update
git checkout phette23 # tracks master branch of fork
git pull # might need to sync fork to homebrew?
set FORMULA marcli # name of the project you're bumping
set VERSION 1.1.0 # semantic version
brew bump-formula-pr --no-fork --url https://github.com/account/$FORMULA/archive/refs/tags/v$VERSION.tar.gz project
@phette23
phette23 / html-email.py
Created November 22, 2022 00:29
demo of sending HTML email in syllabus reminders project
from email.message import EmailMessage
import smtplib
from reminders.config import config
from_address = '[email protected]'
to_address = '[email protected]'
msg = EmailMessage()