diff --git a/.github/workflows/scheduler_daily.yml b/.github/workflows/scheduler_daily.yml index dadc4254..807ae660 100644 --- a/.github/workflows/scheduler_daily.yml +++ b/.github/workflows/scheduler_daily.yml @@ -54,6 +54,7 @@ jobs: - name: ☯️ Cache dojo logos in Japan run: | bundle exec ruby cache_dojo_logos.rb + bundle exec rake cache_data_as_yaml - name: 📍 Generate DojoMap from Earth/Japan data run: | @@ -65,13 +66,24 @@ jobs: git config --global user.name "Yohei Yasukawa" git config --global user.email "yohei@yasslab.jp" git checkout main + + # Gems may update automatically git add Gemfile.lock + + # Cache responses from Japan/Clubs APIs git add dojos_earth.json git add dojos_japan.json git add events_japan.json git add images/dojos + git add _data/earth.yml + + # Save GeoJSON data to render DojoMap git add dojos.geojson + + # Commit changed files above git commit -m '🤖 Upsert Earth/Japan data for DojoMap' + + # Git pull/push the commit to deploy git pull origin main git push origin main fi diff --git a/Rakefile b/Rakefile index e9777484..11332143 100644 --- a/Rakefile +++ b/Rakefile @@ -5,6 +5,7 @@ desc 'Get CoderDojo data on the Earth via Raspberry Pi Clubs API' task(:get_data_from_earth) { ruby 'get_data_from_earth.rb' } task(:get_data_from_japan) { ruby 'get_data_from_japan.rb' } task(:cache_dojo_logos) { ruby 'cache_dojo_logos.rb' } +task(:cache_data_as_yaml) { ruby 'cache_data_as_yaml.rb' } task(:upsert_dojos_geojson) { ruby 'upsert_dojos_geojson.rb' } # GitHub - gjtorikian/html-proofer diff --git a/_data/.gitkeep b/_data/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/_data/earth.yml b/_data/earth.yml new file mode 100644 index 00000000..e69de29b diff --git a/cache_data_as_yaml.rb b/cache_data_as_yaml.rb new file mode 100755 index 00000000..7bf6ebfb --- /dev/null +++ b/cache_data_as_yaml.rb @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'json' +require 'yaml' +require 'fileutils' + +# This script caches the Clubs API's data as YAML format. +# Earth data: from RasPi's Clubs API: https://clubs-api.raspberrypi.org +EARTH_YAML_PATH = '_data/earth.yml' + +# Ensure _data directory exists +FileUtils.mkdir_p('_data') + +# Load Earth data (use string keys, not symbols) +dojos_earth = JSON.load(File.read('dojos_earth.json'), + nil, + symbolize_names: false, + create_additions: false) + +# Save all Earth data as YAML +IO.write(EARTH_YAML_PATH, dojos_earth.to_yaml) +puts "✅ Cached #{dojos_earth.size.to_s.rjust(4)} Earth dojos to #{EARTH_YAML_PATH}" + +# Count Japan dojos for information +dojos_japan = dojos_earth.select { |dojo| dojo['countryCode'] == 'JP' } +puts " (Incl. #{dojos_japan.size.to_s.rjust(4)} Japan's active/inactive dojos)" + +puts +puts "Finished caching JSON data as YAML." +puts diff --git a/earth.json b/earth.json new file mode 100644 index 00000000..441b1df5 --- /dev/null +++ b/earth.json @@ -0,0 +1,4 @@ +--- +layout: none +--- +{{ site.data.earth | jsonify }} \ No newline at end of file diff --git a/japan.json b/japan.json new file mode 100644 index 00000000..1b2f6ea8 --- /dev/null +++ b/japan.json @@ -0,0 +1,4 @@ +--- +layout: none +--- +{{ site.data.earth | where: "countryCode", "JP" | jsonify }} \ No newline at end of file