[robin@laptop ~] $ reddit_created https://www.reddit.com/r/redditisfun/comments/48dk3e/see_actual_date_of_comment_instead_of_2_months/
Mon Feb 29 02:41:34 PM HST 2016
Tue Mar 1 12:41:34 AM GMT 2016
It shows both local time and GMT time.
[robin@laptop ~] $ reddit_created https://www.reddit.com/r/redditisfun/comments/48dk3e/see_actual_date_of_comment_instead_of_2_months/
Mon Feb 29 02:41:34 PM HST 2016
Tue Mar 1 12:41:34 AM GMT 2016
It shows both local time and GMT time.
#!/bin/bash | |
set -o pipefail | |
# Check that jq is installed | |
if ! type -P jq >/dev/null; then | |
echo "error: couldn't find jq on path." | |
exit 1 | |
fi | |
url=$1 | |
# Chop off / from the end | |
url=${url%/} | |
# Add .json to the end | |
url=${url}.json | |
max_attempts=3 | |
success= | |
for (( i=0; i<max_attempts; i++ )); do | |
if created=$(curl -fs "$url" | jq '.[0].data.children.[0].data.created'); then | |
success=Y | |
break | |
fi | |
# Probably got the "Too Many Requests" response | |
# Sleep for a period of time before making next attempt | |
# Increase the duration for each iteration: 5, 10, 15 seconds | |
sleep "$((5 + i*5))" | |
done | |
if [[ $success ]]; then | |
echo "$(date -d @"$created")" | |
echo "$(TZ=GMT date -d @"$created")" | |
else | |
# Must have reached max_attempts | |
echo "Sorry, tried $max_attempts times without success. Probably \"Too Many requests.\"" | |
fi |