diff --git a/bin/pull-arabic b/bin/pull-arabic index 64e7075..cbc6243 100755 --- a/bin/pull-arabic +++ b/bin/pull-arabic @@ -7,16 +7,16 @@ require "paint" ## # Configuration variables. -base_uri = "www.sacred-texts.com" -path = "/isl/uq/%{htm_file}" -dest_path = File.join(__dir__, "..", "src", "arabic", "%{chapter_num}.json") +base_uri = "www.sacred-texts.com" +path = "/isl/uq/%{htm_file}" +dest_path = File.join(__dir__, "..", "src", "arabic", "%{chapter_num}.json") chapter_count = 114 -cool_off = 5 +cool_off = 5 ## # Share a single Net::HTTP instance. -http = Net::HTTP.new(base_uri, 443) -http.use_ssl = true +http = Net::HTTP.new(base_uri, 443) +http.use_ssl = true ## # Helper method. @@ -35,22 +35,22 @@ end def get_request(path, htm_file) Net::HTTP::Get.new( format(path, htm_file: htm_file), - 'Accept' => 'text/html' + "Accept" => "text/html" ) end ## # Helper method. def extract_verses!(res, rows) - doc = Nokogiri::HTML(res.body) - verses = doc.css('table tr td p[align=RIGHT]') + doc = Nokogiri::HTML(res.body) + verses = doc.css("table tr td p[align=RIGHT]") verses.each do |verse| - verse_num = Integer(verse.css('a').inner_text) + verse_num = Integer(verse.css("a").inner_text) verse_txt = verse.text.delete(verse_num.to_s) rows.push([ verse_num, - verse_txt.gsub("\u200F", "").gsub("\u200E", "").strip + verse_txt.delete("\u200F").delete("\u200E").strip ]) end end @@ -58,7 +58,7 @@ end ## # main() 1.upto(chapter_count) do |chapter_num| - htm_file = get_htm_file(chapter_num) + htm_file = get_htm_file(chapter_num) final_dest = format(dest_path, chapter_num:) rows = [] @@ -74,5 +74,3 @@ end print Paint["Chill for #{cool_off} seconds", :blue, :bold], "\n", "\n" sleep cool_off end - - diff --git a/bin/pull-english b/bin/pull-english index 97a6239..a614a9d 100755 --- a/bin/pull-english +++ b/bin/pull-english @@ -7,24 +7,24 @@ require "paint" ## # Configuration variables. -base_uri = "quran.com" -path = "/%{chapter_num}/%{verse_num}" -dest_path = File.join(__dir__, "..", "src", "english", "%{chapter_num}.json") -arab_path = File.join(__dir__, "..", "src", "arabic", "%{chapter_num}.json") +base_uri = "quran.com" +path = "/%{chapter_num}/%{verse_num}" +dest_path = File.join(__dir__, "..", "src", "english", "%{chapter_num}.json") +arab_path = File.join(__dir__, "..", "src", "arabic", "%{chapter_num}.json") chapter_count = 114 -cool_off = 5 +cool_off = 5 ## # Share a single Net::HTTP instance. -http = Net::HTTP.new(base_uri, 443) -http.use_ssl = true +http = Net::HTTP.new(base_uri, 443) +http.use_ssl = true ## # Helper method. def get_request(path, chapter_num, verse_num) Net::HTTP::Get.new( format(path, chapter_num:, verse_num:), - 'Accept' => 'text/html' + "Accept" => "text/html" ) end @@ -38,9 +38,9 @@ end verses.each do |verse_num, _| case res = http.request(get_request(path, chapter_num, verse_num)) when Net::HTTPOK - doc = Nokogiri::HTML(res.body) - el = doc.css("div[class^='TranslationText']").last - text = el.text.gsub(/[0-9]/, '') + doc = Nokogiri::HTML(res.body) + el = doc.css("div[class^='TranslationText']").last + text = el.text.gsub(/[0-9]/, "") rows.push([verse_num, text]) print Paint["OK: ", :green, :bold], text, "\n" else @@ -52,5 +52,3 @@ end File.write(final_dest, JSON.pretty_generate(rows)) print Paint["OK: ", :green, :bold], final_dest, "\n" end - -