Skip to content

Commit 3ee88ec

Browse files
authored
Merge pull request #20 from coderdojo-japan/cache-dojo-data-as-yaml
DojoデータをYAML形式でキャッシュする機能を追加
2 parents 5791a85 + 317fe47 commit 3ee88ec

File tree

7 files changed

+50
-0
lines changed

7 files changed

+50
-0
lines changed

.github/workflows/scheduler_daily.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
- name: ☯️ Cache dojo logos in Japan
5555
run: |
5656
bundle exec ruby cache_dojo_logos.rb
57+
bundle exec rake cache_data_as_yaml
5758
5859
- name: 📍 Generate DojoMap from Earth/Japan data
5960
run: |
@@ -65,13 +66,24 @@ jobs:
6566
git config --global user.name "Yohei Yasukawa"
6667
git config --global user.email "yohei@yasslab.jp"
6768
git checkout main
69+
70+
# Gems may update automatically
6871
git add Gemfile.lock
72+
73+
# Cache responses from Japan/Clubs APIs
6974
git add dojos_earth.json
7075
git add dojos_japan.json
7176
git add events_japan.json
7277
git add images/dojos
78+
git add _data/earth.yml
79+
80+
# Save GeoJSON data to render DojoMap
7381
git add dojos.geojson
82+
83+
# Commit changed files above
7484
git commit -m '🤖 Upsert Earth/Japan data for DojoMap'
85+
86+
# Git pull/push the commit to deploy
7587
git pull origin main
7688
git push origin main
7789
fi

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ desc 'Get CoderDojo data on the Earth via Raspberry Pi Clubs API'
55
task(:get_data_from_earth) { ruby 'get_data_from_earth.rb' }
66
task(:get_data_from_japan) { ruby 'get_data_from_japan.rb' }
77
task(:cache_dojo_logos) { ruby 'cache_dojo_logos.rb' }
8+
task(:cache_data_as_yaml) { ruby 'cache_data_as_yaml.rb' }
89
task(:upsert_dojos_geojson) { ruby 'upsert_dojos_geojson.rb' }
910

1011
# GitHub - gjtorikian/html-proofer

_data/.gitkeep

Whitespace-only changes.

_data/earth.yml

Whitespace-only changes.

cache_data_as_yaml.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env ruby
2+
require 'json'
3+
require 'yaml'
4+
require 'fileutils'
5+
6+
# This script caches the Clubs API's data as YAML format.
7+
# Earth data: from RasPi's Clubs API: https://clubs-api.raspberrypi.org
8+
EARTH_YAML_PATH = '_data/earth.yml'
9+
10+
# Ensure _data directory exists
11+
FileUtils.mkdir_p('_data')
12+
13+
# Load Earth data (use string keys, not symbols)
14+
dojos_earth = JSON.load(File.read('dojos_earth.json'),
15+
nil,
16+
symbolize_names: false,
17+
create_additions: false)
18+
19+
# Save all Earth data as YAML
20+
IO.write(EARTH_YAML_PATH, dojos_earth.to_yaml)
21+
puts "✅ Cached #{dojos_earth.size.to_s.rjust(4)} Earth dojos to #{EARTH_YAML_PATH}"
22+
23+
# Count Japan dojos for information
24+
dojos_japan = dojos_earth.select { |dojo| dojo['countryCode'] == 'JP' }
25+
puts " (Incl. #{dojos_japan.size.to_s.rjust(4)} Japan's active/inactive dojos)"
26+
27+
puts
28+
puts "Finished caching JSON data as YAML."
29+
puts

earth.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
layout: none
3+
---
4+
{{ site.data.earth | jsonify }}

japan.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
layout: none
3+
---
4+
{{ site.data.earth | where: "countryCode", "JP" | jsonify }}

0 commit comments

Comments
 (0)