Module: MagicFormulaInvesting
- Extended by:
- MagicFormulaInvesting
- Included in:
- MagicFormulaInvesting
- Defined in:
- lib/magicformulainvesting.rb,
lib/magicformulainvesting/version.rb,
lib/magicformulainvesting/company_quote.rb
Defined Under Namespace
Classes: CompanyQuote
Constant Summary collapse
- VERSION =
"1.1.0"
Instance Method Summary collapse
Instance Method Details
#run ⇒ Object
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 |
# File 'lib/magicformulainvesting.rb', line 9 def run company_quotes = [] agent = Mechanize.new agent.get('https://www.magicformulainvesting.com/Account/LogOn') do |login_page| page = login_page.form_with(action: '/Account/Logon') do |f| f.Email = ENV['MAGICFORMULA_EMAIL'] f.Password = ENV['MAGICFORMULA_PASSWORD'] end.submit results_page = page.form_with(action: '/Screening/StockScreening') do |f| f.MinimumMarketCap = ENV['MAGICFORMULA_MARKETCAP'] || '50' f.(name: 'Select30')[0].check end.submit require "pp" results_table = results_page.search("table")[-1] results_rows = results_table.search("tbody tr") results_rows.each do |row| data = row.search("td") quote = MagicFormulaInvesting::CompanyQuote.new quote.name = data[0].text quote.ticker = data[1].text quote.market_cap = data[2].text quote.price_from = data[3].text quote.most_recent_quarter_data = data[4].text company_quotes << quote end end table = Terminal::Table.new :headings => ['Name', 'Ticker', 'Market Cap', 'Price From', 'Recent Quarter Data', 'Overview'] company_quotes.each do |quote| table << quote.table_row end puts table end |