diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..94a2dd1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.json \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..9b37379 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source "https://rubygems.org" + +gem "nameday_vvc_pdf_extractor", "~> 0.1", ">= 0.1.1" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..0a91f3d --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,25 @@ +GEM + remote: https://rubygems.org/ + specs: + Ascii85 (1.0.3) + afm (0.2.2) + hashery (2.1.2) + nameday_vvc_pdf_extractor (0.1.1) + pdf-reader (~> 2.1) + pdf-reader (2.1.0) + Ascii85 (~> 1.0.0) + afm (~> 0.2.1) + hashery (~> 2.0) + ruby-rc4 + ttfunk + ruby-rc4 (0.1.5) + ttfunk (1.5.1) + +PLATFORMS + ruby + +DEPENDENCIES + nameday_vvc_pdf_extractor (~> 0.1, >= 0.1.1) + +BUNDLED WITH + 1.16.6 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..db42faa --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +Copyright (c) 2018 Aleksandrs Ļedovskis +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the Aleksandrs Ļedovskis nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL ALEKSANDRS ĻEDOVSKIS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..79a75f6 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# APIs.lv namedays JSON shim + +This script uses [nameday-vvc-pdf-extractor](https://github.com/aleksandrs-ledovskis/nameday-vvc-pdf-extractor) gem to prepare [APIs.lv](http://apis.lv/) compatible namedays JSON extract. +Reason - original API data source is not being updated anymore. + +## Usage (A) + + +## Usage (B) + +Prerequisite - locally downloaded VVC nameday PDF. Check [this page](http://vvc.gov.lv/index.php?route=product/category&path=193_199) for "Latviešu tradicionālo vārdadienu saraksts (PDF)". + +```shell +$ gem install -g +$ VVC_PDF_FILE_PATH=/tmp/vvc.pdf ruby generate_namedays_json.rb > /tmp/output.json +``` + +## License + +BSD-3 diff --git a/generate_namedays_json.rb b/generate_namedays_json.rb new file mode 100644 index 0000000..ecfa155 --- /dev/null +++ b/generate_namedays_json.rb @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "nameday_vvc_pdf_extractor" +require "psych" + +extractor = Nameday::VvcPdfExtractor.new +extractor.read_pdf(ENV["VVC_PDF_FILE_PATH"]) +nameday_hash = extractor.extract + +output = [] + +nameday_hash.each do |month, month_value| + month_value.each do |day, day_value| + next unless day_value + + day_value.each do |name| + output << { + month: month, + day: day, + name: name + } + end + end +end + +puts Psych.to_json(output)