quran-go

Read Qur'an right in the terminal.
git clone http://git.hanabi.in/repos/quran-go.git
Log | Files | Refs | README | LICENSE

commit 739a0a16df6be1471d895a46e4e9ef38fc910a01
parent 2213e51cb00ec1084be494ec8a93680f7f5ab4fa
Author: Agastya Chandrakant <me@hanabi.in>
Date:   Wed, 27 Apr 2022 00:10:27 +0530

Add three cases of verse printing, awaiting answer for
https://github.com/quran/quran.com-api/issues/552

Diffstat:
MPLAN | 11+++++++++--
Mmain.go | 42++++++++++++++++++++++++++----------------
2 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/PLAN b/PLAN @@ -1,4 +1,5 @@ -Available commands: +Available commands +================== + quran + quran 2 @@ -6,6 +7,12 @@ Available commands: + quran 2:10-11 + quran 2:10-11 -lang=ur -Convention: +Convention +========== In the source code (even in the comments), "verse" is used in place of "aayat" since the JSON response of quran.com API says verse. So staying consistent with it. + +Features +======== + ++ Should I support 2:14- to print all verses from 14 till the end of the chapter? diff --git a/main.go b/main.go @@ -20,33 +20,43 @@ func main() { printerr(err) } else { debug(lang) - if err := checkVerseRange(chap, ver1, ver2); err != nil { + if err, maxVerse := checkVerseRange(chap, ver1, ver2); err != nil { printerr(err) } else { if ver1 == 0 { - // Print whole chapter. + // Print whole chapter, ie from 1-maxVerse + for verse := t_verse(1); verse <= maxVerse; verse++ { + printVerse(chap, verse) + } } else if ver1 < ver2 { - // Print the range of verses. + // Print the range of verses, if from ver1 to ver2. + // @TODO check if < or <= ? + for verse := ver1; verse <= ver2; verse++ { + printVerse(chap, verse) + } } else if ver1 == ver2 { - // Print just one verse. + // Print just one verse, if just ver 1. + printVerse(chap, ver1) } } } } -func checkVerseRange(chap t_chap, ver1, ver2 t_verse) (err error) { - if err := checkChapRange(chap); err != nil { - return err +func printVerse(chap t_chap, verse t_verse) { + debug(fmt.Sprintf("Fetching %d:%d...\n", chap, verse)) +} + +func checkVerseRange(chap t_chap, ver1, ver2 t_verse) (err error, maxVerse t_verse) { + if err = checkChapRange(chap); err != nil { + return } - if ver1 > 0 { - maxVerse, err := getChapMaxVerse(chap) - if err != nil { - return err - } - if ver2 > maxVerse { - err = fmt.Errorf("Verse for the chapter %d is out of range. That chapter has verses only till %d.\n", chap, maxVerse) - return err - } + maxVerse, err = getChapMaxVerse(chap) + if err != nil { + return + } + if ver2 > maxVerse { + err = fmt.Errorf("Verse for the chapter %d is out of range. That chapter has verses only till %d.\n", chap, maxVerse) + return } return }