generated from akshaybhalotia/readme-template
-
Notifications
You must be signed in to change notification settings - Fork 6
/
combine_responses.rb
29 lines (23 loc) · 917 Bytes
/
combine_responses.rb
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
27
28
29
# frozen_string_literal: true
require 'json'
puts 'Initiating local processing'
Dir.mkdir('./data') unless Dir.exist?('./data')
path = './responses'
File.write('./data/combined_companies_data.json', '')
File.write('./data/combined_companies_data.json', '[', mode: 'a')
Dir.children(path).each do |file|
next if file == 'yc_batches.json'
puts "Processing #{file}"
file_data = File.read("#{path}/#{file}")
data = JSON.parse(file_data)
useful_data = data['results'][0]['hits']
array_items = if file == Dir.children(path).first
(JSON.generate(useful_data)[1...-1]).to_s
else
",#{JSON.generate(useful_data)[1...-1]}"
end
File.write('./data/combined_companies_data.json', array_items, mode: 'a')
puts "Processed #{file}"
end
File.write('./data/combined_companies_data.json', ']', mode: 'a')
puts 'All data combined into single JSON'