Skip to content

Instantly share code, notes, and snippets.

@dwallraff
Last active January 28, 2024 19:16
Show Gist options
  • Save dwallraff/f88f11b6b10976e44e17de0b2a437912 to your computer and use it in GitHub Desktop.
Save dwallraff/f88f11b6b10976e44e17de0b2a437912 to your computer and use it in GitHub Desktop.
Download puzzle pdfs for remarkable
#! /usr/bin/env bash
#-- Dave Wallraff
# First things first, I'm the realest...
### Download puzzles for reMarkable
# curl -sL dwallraff.com/puzzles | bash
# wrap in a function for curl|bash
do_stuff() {
# Check if rampi is installed
if [ ! "$(command -v rmapi)" ]; then
echo "The rmapi cli is not installed. Aborting..."
exit 1
fi
# Check if op is installed
if [ ! "$(command -v op)" ]; then
echo "The op cli is not installed. Aborting..."
exit 1
fi
# Check if op is logged in
if ! op whoami > /dev/null 2>&1; then
echo "Not logged into 1password"
echo "Please run:"
echo "eval \"\$(op account add --account my.1password.comn --email dave.wallraff@gmail.com --address my.1password.com --signin)\""
exit 1
fi
### Setup a temp dir
TEMP_DIR=$(mktemp -d)
cd "$TEMP_DIR" || die
### Define some URLs
urls=(
https://www.printable-puzzles.com/printable-crossword-puzzles.php
https://www.printable-puzzles.com/printable-cryptograms.php
)
count=0
for url in "${urls[@]}"; do
type=$(echo "$url" | grep -Eo '\/printable\-[a-z-]?+' | cut -c 12-)
echo "downloading $type"
mkdir -p "$type"
cd "$type" || die
for page in $(curl -s "$url" | grep -Eo '\"\/download\.php\S*' | tr -d '"'); do
count=$((count + 1))
slug=$(curl -s https://www.printable-puzzles.com"$page" | grep -Eo "[A-Z0-9]{6,}\.pdf")
# echo "$slug"
curl -s https://www.printable-puzzles.com/dl.php?"$slug" -o "$slug"
done
cd "$TEMP_DIR" || die
done
### Need a seperate block cause these are external PDFs
url="https://www.printable-puzzles.com/printable-logic-puzzles.php"
type=$(echo "$url" | grep -Eo '\/printable\-[a-z-]?+' | cut -c 12-)
echo "downloading $type"
mkdir -p "$type"
cd "$TEMP_DIR"/"$type" || die
for page in $(curl -s "$url" | grep -Eo '\"\/download\.php\S*' | tr -d '"'); do
count=$((count + 1))
slug=$(curl -s https://www.printable-puzzles.com"$page" | grep -Eo '[A-Z0-9]{6,}\.pdf')
url=$(curl -s https://www.printable-puzzles.com"$page" | grep -Eo '\/\/.*[A-Z0-9]{6,}\.pdf' | cut -c 3-)
# echo "$slug"
curl -sL "$url" -o "$slug"
done
### Washington Post Sunday Crossword Puzzle
cd "$TEMP_DIR"/crossword-puzzles || die
if [ "$(date +'%u')" == 7 ]
then
echo "downloading wapo crossword"
count=$((count + 1))
wapodate=$(date +'%y%m%d')
curl -sOJ -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "id=ebirnholz_${wapodate}&set=wapo-eb&theme=wapo&locale=en-US&print=1&checkPDF=true" "https://cdn1.amuselabs.com/wapo/crossword-pdf"
fi
### NY Times Crossword puzzles
cd "$TEMP_DIR"/crossword-puzzles || die
echo "downloading nytimes crosswords"
### Get the last 7 days cause why not
for i in {0..6}; do
count=$((count + 1))
nytimesdate=$(date -d "-$i day" +'%Y-%m-%d')
nytimescookie="$(op item get nytimes_cookie --format json | jq -r '.fields[] | select(.id=="password") | .value')"
crossword_id=$(curl -s "https://www.nytimes.com/svc/crosswords/v6/puzzle/daily/${nytimesdate}.json" -H "cookie: ${nytimescookie}" | jq '.id')
curl -s "https://www.nytimes.com/svc/crosswords/v2/puzzle/${crossword_id}.pdf" -H "cookie: ${nytimescookie}" --output nytimes-"$nytimesdate".pdf
done
### Get a count
cd "$TEMP_DIR" || die
total=$(find ./* -type f | wc -l)
echo
echo "Looked for $count files, got $total files"
### Upload to remarkable
rmapi mput /puzzles
}
do_stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment