diff --git a/bin/json/insert-chapter-metadata b/bin/json/insert-chapter-metadata deleted file mode 100755 index 6c4e704..0000000 --- a/bin/json/insert-chapter-metadata +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -## -# This script inserts metadata about each chapter in -# The Qur'an. The metadata is inserted into the JSON -# for each chapter (eg src/json/en/1.json, src/json/en/2.json, -# src/json/en/3.json, ...). -# -# The metadata is an object that's inserted as the first element -# in an array that otherwise contains the contents of a chapter. - -## -# Set process name - primarily for the "ps" command -Process.setproctitle("quran-pull (insert-chapter-metadata)") - -## -# Dependencies -require "bundler/setup" -require "json" -require "paint" -require "io/line" - -## -# Utils -def parse_json(path)= JSON.parse(File.read(path)) - -## -# Configuration variables -lc_glob = ARGV[0] || "*" -base_dir = File.join("src", "json") -chapters = parse_json(File.join(base_dir, "chapter-metadata.json")) -dirs = Dir.glob(File.join(base_dir, lc_glob)).select { File.directory?(_1) } -line = IO::Line.new($stdout) - -print "\n", " " * 3, Paint["Add metadata", :bold], "\n\n" -print "Locale", " " * 3 -print "Location", "\n" -dirs.each do |dir| - 1.upto(114) do |number| - ch = chapters[number - 1] - lc = File.basename(dir) - fp = File.join(dir, "#{number}.json") - line.rewind.print File.basename(dir), " " * 7, File.join(lc, "#{number}.json").center(9) - contents = parse_json(fp) - contents.unshift(ch) - File.write(fp, JSON.pretty_generate(contents)) - sleep 0.01 - end - puts -end diff --git a/bin/json/insert-chapters-data b/bin/json/insert-chapters-data deleted file mode 100755 index 4d1463f..0000000 --- a/bin/json/insert-chapters-data +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -## -# This script requests information about the chapters of -# The Qur'an from the website https://quran.com, and writes -# the result to src/json/chapters-data.json. - -## -# Set process name - primarily for the "ps" command -Process.setproctitle("quran-pull (pull-chapters-data)") - -## -# Dependencies -require "bundler/setup" -require "json" -require "paint" -require "io/line" - -## -# Utils -def parse_json(path)= JSON.parse(File.read(path)) - -## -# Configuration variables -base_dir = File.join("src", "json") -chapters = parse_json(File.join(base_dir, "chapters-data.json")) -dirs = Dir.glob(File.join(base_dir, "*")).select { File.directory?(_1) } -line = IO::Line.new($stdout) - -print "\n", " " * 4, Paint["Add chapter / surah metadata", :bold], "\n\n" -print " " * 8, "Locale" -print " " * 3, "Location", "\n" -dirs.each do |dir| - 1.upto(114) do |number| - ch = chapters[number - 1] - lc = File.basename(dir) - line.rewind.print " " * 8, File.basename(dir), " " * 7, File.join(lc, "#{number}.json").center(9) - contents = parse_json(File.join(dir, "#{number}.json")) - contents.unshift(ch) - sleep 0.01 - end - puts -end diff --git a/bin/json/pull-chapter-metadata b/bin/json/pull-chapter-metadata deleted file mode 100755 index 5e53313..0000000 --- a/bin/json/pull-chapter-metadata +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -## -# This script requests information about the chapters of -# The Qur'an from the website https://quran.com, and writes -# the result to src/json/chapter-metadata.json. - -## -# Set process name - primarily for the "ps" command -Process.setproctitle("quran-pull (pull-chapter-metadata)") - -## -# Dependencies -require "bundler/setup" -require "net/http" -require "nokogiri" -require "json" -require "paint" - -## -# Configuration variables. -base_uri = "quran.com" -dest = File.join('src', 'json', 'chapter-metadata.json') - -## -# Share a single Net::HTTP instance. -http = Net::HTTP.new(base_uri, 443) -http.use_ssl = true - -## -# Utils -request_chapters = ->(path) do - res = http.request_get(path) - json = Nokogiri.HTML(res.body) - .css("script[type='application/json']") - .inner_text - JSON.parse(json).dig('props', 'pageProps', 'chaptersData') -end - -## -# Chapter data -en_chapters = request_chapters.call('/') -ar_chapters = request_chapters.call('/ar') - -## -# Parse chapter data -parsed = en_chapters.map do |key, chapter| - { - id: key, - place_of_revelation: chapter['revelationPlace'], - transliterated_name: chapter['transliteratedName'], - translated_name: chapter['translatedName'], - verse_count: chapter['versesCount'], - slug: chapter['slug'], - codepoints: ar_chapters[key]['translatedName'].codepoints - } -end - -## -# Write result -File.write(dest, JSON.pretty_generate(parsed)) -print Paint["OK ", :green, :bold], dest, "\n"