-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcache_data_as_yaml.rb
More file actions
executable file
·26 lines (21 loc) · 863 Bytes
/
cache_data_as_yaml.rb
File metadata and controls
executable file
·26 lines (21 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/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'
# 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