Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/scheduler_daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file added _data/.gitkeep
Empty file.
Empty file added _data/earth.yml
Empty file.
29 changes: 29 additions & 0 deletions cache_data_as_yaml.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions earth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
layout: none
---
{{ site.data.earth | jsonify }}
4 changes: 4 additions & 0 deletions japan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
layout: none
---
{{ site.data.earth | where: "countryCode", "JP" | jsonify }}