Compare commits
No commits in common. "main" and "0.2.3" have entirely different histories.
@ -1 +0,0 @@
|
|||||||
nim 1.6.20
|
|
@ -1,6 +1,6 @@
|
|||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "0.3.0"
|
version = "0.2.3"
|
||||||
author = "Jonathan Bernard"
|
author = "Jonathan Bernard"
|
||||||
description = "Simple Nim CLI wrapper around the ESV API (api.esv.org)"
|
description = "Simple Nim CLI wrapper around the ESV API (api.esv.org)"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
@ -11,7 +11,7 @@ bin = @["esv_api"]
|
|||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
requires "nim >= 1.6.10"
|
requires "nim >= 1.6.10"
|
||||||
requires @["docopt", "nimquery", "zero_functional"]
|
requires @["docopt", "zero_functional"]
|
||||||
|
|
||||||
# dependencies from git.jdb-software.com/jdb/nim-packages.git
|
# dependencies from git.jdb-software.com/jdb/nim-packages.git
|
||||||
requires @["cliutils"]
|
requires @["cliutils"]
|
||||||
|
@ -32,36 +32,6 @@ proc formatMarkdown(raw: string): string =
|
|||||||
result = (wrapped.splitLines --> map("> " & it)).
|
result = (wrapped.splitLines --> map("> " & it)).
|
||||||
join("\p") & "\p> -- *" & reference & " (ESV)*"
|
join("\p") & "\p> -- *" & reference & " (ESV)*"
|
||||||
|
|
||||||
proc formatPlain(raw: string, keepVerseNumbers = true): string =
|
|
||||||
var reference = ""
|
|
||||||
var inVerse = false
|
|
||||||
var verseLines = newSeq[string]()
|
|
||||||
|
|
||||||
for line in raw.splitLines:
|
|
||||||
if reference.len == 0: reference = line.strip
|
|
||||||
if inVerse:
|
|
||||||
if line.startsWith("Footnotes"): inVerse = false
|
|
||||||
elif line.isEmptyOrWhitespace and verseLines[^1] != "":
|
|
||||||
verseLines.add("")
|
|
||||||
elif not line.match(re"^\s+[^\s]"): continue
|
|
||||||
elif line.match(re"$(.*)\(ESV\)$"): verseLines.add(line[0 ..< ^5])
|
|
||||||
else: verseLines.add(line)
|
|
||||||
elif line.match(re"^\s+\[\d+\]"):
|
|
||||||
inVerse = true
|
|
||||||
verseLines.add(line)
|
|
||||||
|
|
||||||
let wrapped = (verseLines -->
|
|
||||||
map(if it.len > 90: it.strip else: it & " ").
|
|
||||||
map(
|
|
||||||
if keepVerseNumbers:
|
|
||||||
it.multiReplace([(re"\((\d+)\)", ""), (re"\[(\d+)\]", "$1")])
|
|
||||||
else:
|
|
||||||
it.multiReplace([(re"\((\d+)\)", ""), (re"\[(\d+)\]", "")])).
|
|
||||||
map(wrapWords(it, maxLineWidth = 74, newLine = "\p"))).join("\p")
|
|
||||||
|
|
||||||
result = (wrapped.splitLines --> map(it)).
|
|
||||||
join("\p") & "\p– " & reference & " (ESV)"
|
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
const USAGE = """Usage:
|
const USAGE = """Usage:
|
||||||
esv_api <reference> [options]
|
esv_api <reference> [options]
|
||||||
@ -74,7 +44,7 @@ Options:
|
|||||||
command line for debugging purposes.
|
command line for debugging purposes.
|
||||||
|
|
||||||
-f, --output-format <format> Select a specific output format. Valid values
|
-f, --output-format <format> Select a specific output format. Valid values
|
||||||
are 'raw', 'markdown', 'plain', 'reading'.
|
are 'raw', 'markdown', 'plain'.
|
||||||
|
|
||||||
-t, --esv-api-token <token> Provide the API token on the command line. By
|
-t, --esv-api-token <token> Provide the API token on the command line. By
|
||||||
default this will be read either from the
|
default this will be read either from the
|
||||||
@ -89,7 +59,7 @@ Options:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
let args = docopt(USAGE, version = "0.3.0")
|
let args = docopt(USAGE, version = "0.2.3")
|
||||||
|
|
||||||
if args["--debug"]:
|
if args["--debug"]:
|
||||||
consoleLogger.levelThreshold = lvlDebug
|
consoleLogger.levelThreshold = lvlDebug
|
||||||
@ -116,11 +86,6 @@ Options:
|
|||||||
|
|
||||||
let formattedPassages =
|
let formattedPassages =
|
||||||
case $args["--output-format"]:
|
case $args["--output-format"]:
|
||||||
of "plain":
|
|
||||||
respJson["passages"].getElems --> map(formatPlain(it.getStr))
|
|
||||||
of "reading":
|
|
||||||
respJson["passages"].getElems -->
|
|
||||||
map(formatPlain(it.getStr, keepVerseNumbers = false))
|
|
||||||
of "text":
|
of "text":
|
||||||
respJson["passages"].getElems -->
|
respJson["passages"].getElems -->
|
||||||
map(it.getStr.multiReplace([(re"\[(\d+)\]", "$1")]))
|
map(it.getStr.multiReplace([(re"\[(\d+)\]", "$1")]))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user