From 820111e2492c7d2f2252d391408c8792c5954219 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Fri, 30 Sep 2022 15:44:47 -0300 Subject: [PATCH] insert-chapters-data: wip. --- bin/json/insert-chapters-data | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 bin/json/insert-chapters-data diff --git a/bin/json/insert-chapters-data b/bin/json/insert-chapters-data new file mode 100755 index 0000000..b2470e0 --- /dev/null +++ b/bin/json/insert-chapters-data @@ -0,0 +1,44 @@ +#!/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_relative "../../binlib/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