Add -o, --overwrite option

This commit is contained in:
0x1eef 2023-02-09 06:35:40 -03:00
parent b3bdf0b83a
commit 729453d5f8
4 changed files with 8 additions and 4 deletions

1
.gitignore vendored
View file

@ -1,3 +1,2 @@
share/quran-json/TheQuran/
*.db

View file

@ -14,11 +14,12 @@ class Pull
def self.cli(argv)
op = nil
options = Ryo({locale: "en"})
options = Ryo({locale: "en", overwrite: false})
OptionParser.new(nil, 26, " " * 2) do |o|
o.banner = "Usage: quran-json pull [OPTIONS]"
op = o
o.on("-l", "--locale LOCALE", "ar, en, pt, or fa (default: en)")
o.on("-o", "--overwrite", "Overwrite existing JSON files that might exist (default: no)")
end.parse(argv, into: options)
options
rescue
@ -54,6 +55,10 @@ class Pull
http.finish
end
def skip?(surah_no)
exist?(surah_no) && !options.overwrite
end
def exist?(surah_no)
File.exist? File.join(quran_dir, options.locale, "#{surah_no}.json")
end

View file

@ -16,7 +16,7 @@ def main(argv)
cmd = Pull.new(Pull.cli(argv))
cmd.keepalive do
1.upto(114) do |surah_no|
next if cmd.exist?(surah_no)
next if cmd.skip?(surah_no)
rows = []
1.upto(cmd.count[surah_no]) do |ayah_no|
res = cmd.pull_ayah(surah_no, ayah_no)

View file

@ -15,7 +15,7 @@ def main(argv)
cmd = Pull.new(Pull.cli(argv))
cmd.keepalive do
1.upto(114) do |surah_no|
next if cmd.exist?(surah_no)
next if cmd.skip?(surah_no)
rows = []
res = cmd.pull_surah(surah_no)
rows.concat(grep(res).map.with_index(1) { [_2, _1] })