Skip to content

Instantly share code, notes, and snippets.

@jquave
Created December 18, 2016 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jquave/f403bdd99a080af763c0fd5844f084cd to your computer and use it in GitHub Desktop.
Save jquave/f403bdd99a080af763c0fd5844f084cd to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
module WDF
class WFGet
def self.current_quarter
yr = Date.today.year
if yr >=10
4
elsif yr >= 7
3
elsif yr >= 4
2
else
1
end
end
def self.todays_edgar_url
# Current quarter, 1 - 4
qtr_num = self.current_quarter
# Current year 2016 format
yr = Date.today.year
# Filename from date
filename = Date.today.strftime("%Y%m%d") + ".nc.tar.gz"
"https://www.sec.gov/Archives/edgar/Feed/#{yr}/QTR#{qtr_num}/#{filename}"
end
end
class Filing
attr_accessor :primary_doc_url, :index_url, :company, :cik, :date_filed
def initialize(company, cik, date_filed, filing_path)
self.index_url = "http://www.sec.gov/Archives/#{filing_path}"
self.primary_doc_url = self.index_url.gsub("-","").gsub(".txt","/primary_doc.xml")
self.company = company
self.cik = cik
self.date_filed = date_filed
end
end
class FilingIndex
attr_accessor :filings
def initialize(filename)
self.filings = []
parse_filing(filename)
end
def parse_filing(filename)
out = ""
text = File.open(filename).read
text.gsub!(/\r\n?/, "\n")
text.each_line do |line|
parts = line.split(" ").uniq
if parts[0] == "D"
self.filings << Filing.new(parts[2], parts[3], parts[4], parts[5])
end
end
puts "Added #{self.filings.length} Form D filings"
puts "First filing url: #{self.filings[0].primary_doc_url}"
puts "First filing name: #{self.filings[0].company}"
end
end
end
WDF::FilingIndex.new('form.20161216.idx')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment