Skip to content

Instantly share code, notes, and snippets.

@jcbrinfo
Last active June 28, 2016 16:16
Show Gist options
  • Select an option

  • Save jcbrinfo/d94ee720f6b941730456fd0d3785334c to your computer and use it in GitHub Desktop.

Select an option

Save jcbrinfo/d94ee720f6b941730456fd0d3785334c to your computer and use it in GitHub Desktop.
List Gist Updates
https://api.github.com/gists/<gist 1 ID>
https://api.github.com/gists/<gist 2 ID>
https://api.github.com/gists/<…>

List Gist Updates

Example: ./whatsnew-gist '2 hours ago' < gist-urls.txt

Use with moderation: Rate limits for unauthenticated IP addresses are very low (60 requests per hour as of 2016-06-20).

#! /bin/bash
# NAME
# whatsnew - return URLs of resources that changed since the specified
# date
#
# SYNOPSIS
# whatsnew date
#
# STANDARD INPUT
# URLs to look for
#
# STANDARD OUTPUT
# Changed resources
set -e
ref_date="$(date -u -Iseconds -d "$1")"
# `read` tries to tokenize lines. But, since lines are URLs (should not contain
# spacing) and we use the (non-standard) `-r` option (disables meaning of
# backslashes), it does the job here.
while IFS='' read -r url || [[ -n "${url}" ]]; do
last_modified="$(curl -sI -- "${url}" | tr -d '\r' | sed -En 's/^Last-Modified: (.*)$/\1/Ip' | xargs -d '\n' -- date -u -Iseconds -d)"
if [ "${last_modified}" '>' "${ref_date}" ]; then
printf '%s\n' "${url}"
fi
done
#! /bin/sh
./whatsnew "$1" | sed 's|^https://api.github.com/gists/|https://gist.github.com/|'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment