Skip to content

Commit 74c155e

Browse files
committed
add lookup result
1 parent 3c95a5f commit 74c155e

File tree

3 files changed

+777
-11
lines changed

3 files changed

+777
-11
lines changed

Rakefile

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,43 @@ OG_IDS = [
1111
'OG-2021-USCIS'
1212
]
1313
INDEX_PATH = './build/index.json'
14+
LOOKUP_PATH = './build/anum_lookup.csv'
1415
HTML_PATH = './build/index.html'
1516
TEMPLATE_PATH = './lib/template.html'
1617

18+
FETCHED_OG_INDEXES = OG_IDS.map { |id| { id => JSON.parse(HTTParty.get("https://migrants-and-the-state.github.io/#{id.downcase}/index.json").body) } }.inject(:merge)
19+
1720
def formatted_datetime(time = Time.now)
1821
fmt_date = "#{time.month}/#{time.day}/#{time.year}"
1922
fmt_time = "#{time.hour}:#{time.min.to_s.rjust(2, '0')}#{time.zone}"
2023
"#{fmt_date} at #{fmt_time}"
2124
end
2225

2326
namespace :build do
27+
desc 'build aggregated list of anums and order_group ids'
28+
task :anums_lookup do
29+
lookup = []
30+
FETCHED_OG_INDEXES.each { |og_id,index| index.each { |afile| lookup << [afile['id'],og_id]} }
31+
puts "Writing anum lookup table to #{LOOKUP_PATH}"
32+
File.open(LOOKUP_PATH, 'w') do |file|
33+
file.puts "anumber,og_id"
34+
lookup.each { |pair| file.puts pair.join(",")}
35+
end
36+
puts "\nDone ✓\n"
37+
end
38+
2439
desc 'build aggregated index'
2540
task :index do
26-
index = []
27-
28-
OG_IDS.each do |og_id|
29-
url = "https://migrants-and-the-state.github.io/#{og_id.downcase}/index.json"
30-
hashes = JSON.parse(HTTParty.get(url).body)
31-
hashes.map! { |h| h['order_group'] = og_id; h }
32-
puts "Adding #{hashes.length} items from #{og_id} to the index"
33-
hashes.each { |hash| index << hash }
41+
aggregate_index = []
42+
43+
FETCHED_OG_INDEXES.each do |og_id, index|
44+
index.map! { |hash| hash['order_group'] = og_id; hash }
45+
puts "Adding #{index.length} items from #{og_id} to the aggregate index"
46+
index.each { |hash| aggregate_index << hash }
3447
end
3548

36-
puts "Writing aggregated index with #{index.length} items to #{INDEX_PATH}"
37-
File.open(INDEX_PATH, 'w') { |file| file.write JSON.pretty_generate(index) }
49+
puts "Writing aggregated index with #{aggregate_index.length} items to #{INDEX_PATH}"
50+
File.open(INDEX_PATH, 'w') { |file| file.write JSON.pretty_generate(aggregate_index) }
3851
puts "\nDone ✓\n"
3952
end
4053

@@ -53,6 +66,7 @@ namespace :build do
5366

5467
desc 'build everything'
5568
task :all do
69+
Rake::Task['build:anums_lookup'].execute
5670
Rake::Task['build:index'].execute
5771
Rake::Task['build:html'].execute
5872
end

0 commit comments

Comments
 (0)