Add "parse_cli"

This commit is contained in:
0x1eef 2023-02-13 10:47:09 -03:00
parent 5a2d637644
commit df762bc882
3 changed files with 20 additions and 4 deletions

View file

@ -25,9 +25,9 @@ def main(argv)
case argv[0]
when "pull"
options = Quran::JSON::Pull.cli(argv[1..])
cli = Quran::JSON::Pull.cli(argv[1..])
sources.each do |locale, source|
case options.locale
case cli.locale
when locale
wait spawn(libexec_dir, source["http"]["hostname"], *argv[1..])
end

View file

@ -4,16 +4,24 @@ require File.join(lib_dir, "quran", "json")
require "optparse"
require "nokogiri"
##
# Grep for ayah content
def grep(res)
html = Nokogiri::HTML(res.body)
el = html.css("div[class^='TranslationText']").last
el.text.gsub(/[0-9]/, "")
end
##
# CLI parser
def parse_cli(argv)
Quran::JSON::Pull.cli(argv)
end
##
# main
def main(argv)
cmd = Quran::JSON::Pull.new(Quran::JSON::Pull.cli(argv))
cmd = Quran::JSON::Pull.new parse_cli(argv)
cmd.keepalive do
1.upto(114) do |surah_no|
if cmd.keep?(surah_no)

View file

@ -4,6 +4,8 @@ require File.join(lib_dir, "quran", "json")
require "optparse"
require "nokogiri"
##
# Grep for ayah content
def grep(res)
sel = "table[dir='ltr'] tr td div:last-child, " \
"table[dir='rtl'] tr td div:last-child"
@ -11,10 +13,16 @@ def grep(res)
html.css(sel).map { _1.text.strip.gsub(/^[0-9]+\.\s*/, "") }
end
##
# CLI parser
def parse_cli(argv)
Quran::JSON::Pull.cli(argv)
end
##
# main
def main(argv)
cmd = Quran::JSON::Pull.new(Quran::JSON::Pull.cli(argv))
cmd = Quran::JSON::Pull.new parse_cli(argv)
cmd.keepalive do
1.upto(114) do |surah_no|
if cmd.keep?(surah_no)