DEV Community

Discussion on: Bhagavad Gita API

Collapse
vinayakgadkari profile image
Vinayak Gadkari
@echo off
setlocal enabledelayedexpansion

@REM A quick batch file to print summary and translations for a random chapter and verse.
@REM Uses httpie for REST, jq for JSON and sfk for colour output.

set ROOT_URL=https://bhagavadgita.theaum.org
set MAX_CHAPTERS=18
set /a RANDOM_CHAPTER=%RANDOM% %%%MAX_CHAPTERS% + 1

for /f "tokens=1" %%i in ('http -b %ROOT_URL%/chapter/%RANDOM_CHAPTER% ^| jq -r ".data[0].verses_count"') do set MAX_VERSES=%%i
set /a RANDOM_VERSE=%RANDOM% %%%MAX_VERSES% + 1

sfk echo "[Green]Summary for chapter %RANDOM_CHAPTER%"
http -b https://bhagavadgita.theaum.org/chapter/summaries/%RANDOM_CHAPTER% | jq -r ".data[0].summary"

sfk echo "[Green]Translations for chapter %RANDOM_CHAPTER% and verse %RANDOM_VERSE%"
http -b %ROOT_URL%/text/translations/%RANDOM_CHAPTER%/%RANDOM_VERSE% > %TEMP%\gita-chosen-version.json
type %TEMP%\gita-chosen-version.json | jq -r ".data[] | .author + \"$\" + .translation | gsub(\"[\\n\\t]\"; \"\")" > %TEMP%\gita-chosen-version.csv
for /f "tokens=1,2 delims=$" %%i in ('type %TEMP%\gita-chosen-version.csv') do (
  set AUTHOR=%%i
  set TRANSLATION=%%j

  sfk echo "[Blue]!AUTHOR!"
  echo !TRANSLATION!
)
Enter fullscreen mode Exit fullscreen mode
Collapse
theaum profile image
TheAum Author

Thank you for this!