Last active
May 18, 2019 21:14
-
-
Save RAnders00/9ca4ceeef8dd9aa4606637324c01f487 to your computer and use it in GitHub Desktop.
Overrustle channellogs downloader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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