Skip to content

Instantly share code, notes, and snippets.

@raffifu
Created May 7, 2022 16:01
Show Gist options
  • Save raffifu/c142fba034308600a6981c843cdc34d5 to your computer and use it in GitHub Desktop.
Save raffifu/c142fba034308600a6981c843cdc34d5 to your computer and use it in GitHub Desktop.
shuzhi custom script
#!/bin/bash
# Modified from original shuzhi.sh [https://github.com/tuberry/shuzhi/blob/main/shuzhi%40tuberry/shuzhi.sh]
# API from https://github.com/lukePeavey/quotable
res=$(curl -s https://api.quotable.io/random?maxLength=80)
content=$(echo $res | jq -r .content)
test -z "$content" && exit 1
author=$(echo $res | jq -r .author)
gap='<span font=\"0.4em\"> </span>\n'
# `SZ_BGCOLOR` is the bgcolor of wallpaper
title='<span font=\"0.45em\" bgcolor=\"#b45a56\" fgcolor=\"SZ_BGCOLOR\">'$author'</span>'
# format for vertical view
vcontent=$(echo $content | sed -r 's/[,。:;?、!]/\n/g;s/[《》“”]//g;' | sed -r '/^\s*$/d' | sed -z 's/\n/\\n/g')
printf '{"vtext":"%s%s%s","htext":"%s\\n%s%s"}' "$vcontent" "$gap" "$title" "$content" "$gap" "$title"
#!/bin/sh
# Modified from original shuzhi.sh [https://github.com/tuberry/shuzhi/blob/main/shuzhi%40tuberry/shuzhi.sh]
# API from https://alquran.cloud
surahNumber=$(shuf -i 74-114 -n 1)
res=$(curl -s https://api.alquran.cloud/v1/surah/$surahNumber)
resTranslate=$(curl -s https://api.alquran.cloud/v1/surah/$surahNumber/en.sahih)
totalAyah=$(echo $res | jq -r .data.numberOfAyahs)
ayahNumber=$(shuf -i 1-$totalAyah -n 1)
ayah=$(echo $res | jq -r .data.ayahs[$ayahNumber].text)
ayahTranslate=$(echo $resTranslate | jq -r .data.ayahs[$ayahNumber].text)
surahName=$(echo $res | jq -r .data.englishName)
surahTranslate=$(echo $res | jq -r .data.englishNameTranslation)
gap='<span font=\"0.4em\"> </span>\n'
translate='<span font=\"0.45em\">'$ayahTranslate'</span>'
surah='<span font=\"0.45em\">'$surahName' - '$surahTranslate' ('$surahNumber':'$ayahNumber')</span>'
# format for vertical view
vcontent=$(echo $ayah | sed -r 's/[,。:;?、!]/\n/g;s/[《》“”]//g;' | sed -r '/^\s*$/d' | sed -z 's/\n/\\n/g')
printf '{"vtext":"%s%s%s","htext":"%s\\n%s%s%s%s"}' "$vcontent" "$gap" "$translate" "$ayah" "$gap" "$translate" "$gap" "$surah"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment