forked from toddwschneider/sec-13f-filings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minimal_db_seeder.rb
50 lines (38 loc) · 1.23 KB
/
minimal_db_seeder.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class MinimalDbSeeder
DEFAULT_CIKS = %w(
0000102909
0001067983
0001167483
0001603466
)
attr_reader :ciks, :periods
def initialize(ciks: DEFAULT_CIKS, periods: nil)
@ciks = Array.wrap(ciks)
@periods = periods || (0..3).map do |i|
date = Date.today - (3 * i).months
{year: date.year, quarter: (date.month - 1) / 3 + 1}
end
end
def seed_minimal_db!
start_time = Time.zone.now
puts "#{start_time}: beginning minimal db seed, might take a few minutes…"
periods.each do |p|
year = p.fetch(:year)
quarter = p.fetch(:quarter)
puts "#{Time.zone.now}: importing 13Fs filed in #{year} Q#{quarter}"
ThirteenF.import_filings!(filing_year: year, filing_quarter: quarter)
end
puts "#{Time.zone.now}: queueing jobs for sample managers"
ThirteenF.process_unprocessed_filings!(ciks: ciks)
puts "#{Time.zone.now}: processing filings data"
Delayed::Worker.new.work_off(1000)
puts "#{Time.zone.now}: deleting unprocessed filings"
ThirteenF.
unprocessed.
where("created_at > ?", start_time).
where.not(cik: ciks).
delete_all
ThirteenFFiler.refresh!
puts "#{Time.zone.now}: done, minimal db now available"
end
end