5
6
mirror of https://github.com/trueChristian/daily-scripture.git synced 2025-01-24 12:58:25 +00:00

Adds more RANDOM

This commit is contained in:
Llewellyn van der Merwe 2023-04-19 14:43:45 +02:00
parent 87b8a9595d
commit dc5d24274c
Signed by: Llewellyn
GPG Key ID: A9201372263741E7

View File

@ -84,17 +84,19 @@ VERSION_DIR="$DIR/../scripture/${VERSION}"
# only load if not already given
if [ -z "${TODAY_S_SCRIPTURE}" ]; then
#████████████████████████████████████████████████████████████████ RANDOM ███
# set a random temp file
sort -R -k1 -b "${SORTED}" >"${TMP}"
# get the first line
TODAY_S_SCRIPTURE=$(head -n 1 "${TMP}")
# only if not a test
if (("$DRY_RUN" == 0)); then
# remove the verse
sed -i -e '1,1d' "${TMP}"
# add to used verses
[ -f "${USED}" ] && echo "$TODAY_S_SCRIPTURE" >>"${USED}" || echo "$TODAY_S_SCRIPTURE" >"${USED}"
fi
# set a random temp file
sort -R -k1 -b "${SORTED}" >"${TMP}"
# get a random number between 1 and 1900
RANDOM_LINE=$((RANDOM % 1900 + 1))
# get the line corresponding to the random number
TODAY_S_SCRIPTURE=$(sed -n "${RANDOM_LINE}{p;q}" "${TMP}")
# only if not a test
if (("$DRY_RUN" == 0)); then
# remove the verse
sed -i -e "${RANDOM_LINE},${RANDOM_LINE}d" "${TMP}"
# add to used verses
[ -f "${USED}" ] && echo "$TODAY_S_SCRIPTURE" >>"${USED}" || echo "$TODAY_S_SCRIPTURE" >"${USED}"
fi
#███████████████████████████████████████████████████ SIX MONTH RETENTION ███
# check test behaviour