Skip to content

Instantly share code, notes, and snippets.

@RAnders00
Last active May 18, 2019 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RAnders00/9ca4ceeef8dd9aa4606637324c01f487 to your computer and use it in GitHub Desktop.
Save RAnders00/9ca4ceeef8dd9aa4606637324c01f487 to your computer and use it in GitHub Desktop.
Overrustle channellogs downloader
#!/bin/bash
channel="$1"
start="$2"
end="$3"
function validate {
[ -n "$channel" ] && [ -n "$start" ] && [ -n "$end" ]
}
if ! validate; then
echo >&2 "Usage: $0 channelName 2018-06-01 2019-01-01"
exit
fi
function dateMillis {
date -d "$1" +%s
}
# so that invalid date formats that make date fail
# kill the script
set -e
startMillis="$(dateMillis "$start")"
endMillis="$(dateMillis "$end")"
if [[ "$startMillis" -gt "$endMillis" ]]; then
echo >&2 "End date is not higher than start date"
exit 2
fi
set +e
normalizedEnd="$(date -d "$end" +%Y-%m-%d)"
function generateDateSequence {
i=0
while true; do
date -d "$start $i days" '+https://overrustlelogs.net/$channel%%20chatlog/%B%%20%Y/%Y-%m-%d.txt'
if [[ "$(date -d "$start $i days" '+%s')" -eq "$endMillis" ]]; then
break
fi
i="$(("$i" + 1))"
done
}
curl $(generateDateSequence | tr '\n' ' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment