-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathget_data_from_japan.rb
More file actions
executable file
·25 lines (21 loc) · 848 Bytes
/
get_data_from_japan.rb
File metadata and controls
executable file
·25 lines (21 loc) · 848 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
#!/usr/bin/env ruby
require 'net/http'
require 'json'
BASE_URL = 'https://coderdojo.jp'
DOJOS_DATA = JSON.parse Net::HTTP.get(URI.parse "#{BASE_URL}/dojos.json"), symbolize_names: true
DOJOS_JSON = JSON.pretty_generate DOJOS_DATA.sort_by{|dojo| dojo[:id]}
EVENTS_DATA = JSON.parse Net::HTTP.get(URI.parse "#{BASE_URL}/events.json"), symbolize_names: true
EVENTS_JSON = JSON.pretty_generate EVENTS_DATA.sort_by{|dojo| dojo[:id]}
File.open("_data/dojos_japan.json", "w") { |file| file.write(DOJOS_JSON) }
File.open("_data/events_japan.json", "w") { |file| file.write(EVENTS_JSON) }
# Show next step for developers
puts DOJOS_JSON
puts ''
puts 'Check out JSON data you fetched by:'
puts '$ cat _data/dojos_japan.json'
puts ''
puts EVENTS_JSON
puts ''
puts 'Check out JSON data you fetched by:'
puts '$ cat _data/events_japan.json'
puts ''