diff --git a/.gitignore b/.gitignore index 10965d1..466a2e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -share/quran-json/TheQuran/ *.db diff --git a/lib/quran-json/pull.rb b/lib/quran-json/pull.rb index 7f14e3c..7b6ce7a 100644 --- a/lib/quran-json/pull.rb +++ b/lib/quran-json/pull.rb @@ -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 diff --git a/libexec/quran-json/quran.com b/libexec/quran-json/quran.com index 5892bfb..b26b19e 100755 --- a/libexec/quran-json/quran.com +++ b/libexec/quran-json/quran.com @@ -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) diff --git a/libexec/quran-json/searchtruth.com b/libexec/quran-json/searchtruth.com index 7300159..a865b5a 100755 --- a/libexec/quran-json/searchtruth.com +++ b/libexec/quran-json/searchtruth.com @@ -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] })