<commit_before>$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../lib'))
require 'invoice/invoicer'
require 'connector/xero'
require 'configuration'
require 'model/company'

options = {:site => 'https://api.xero.com',
           :request_token_path => "/oauth/RequestToken",
           :access_token_path  => "/oauth/AccessToken",
           :authorize_path     => "/oauth/Authorize",
           :signature_method => 'RSA-SHA1',
           :private_key_file => '/Users/thenrio/src/ruby/spike-on-xero/keys/xero.rsa'}
consumer_key = '<KEY>0M2JHNDQ0MMJHY2NLMT'
secret_key = '<KEY>'
connector = Connector::Xero.new(consumer_key, secret_key, options)

invoicer = Invoicer.new(connector)
Configuration.new :path => '/Users/thenrio/src/ruby/agile-france-database/prod.db'
invoices = []
Company.all.each do |company|
  invoices << invoicer.invoice_company(company)
end
<commit_msg>add mail to report execution bleh, script is becoming ugly<commit_after>$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../lib'))
require 'invoice/invoicer'
require 'connector/xero'
require 'configuration'
require 'model/company'

options = {:site => 'https://api.xero.com',
           :request_token_path => "/oauth/RequestToken",
           :access_token_path  => "/oauth/AccessToken",
           :authorize_path     => "/oauth/Authorize",
           :signature_method => 'RSA-SHA1',
           :private_key_file => '/Users/thenrio/src/ruby/spike-on-xero/keys/xero.rsa'}
consumer_key = '<KEY>'
secret_key = '<KEY>'
connector = Connector::Xero.new(consumer_key, secret_key, options)

@invoicer = Invoicer.new(connector)
Configuration.new :path => '/Users/thenrio/src/ruby/agile-france-database/prod.db'
invoices = []

def invoice(invoices)
  Company.all.each do |company|
    invoices << @invoicer.invoice_company(company)
  end
end

require 'mailer'
mail_options = {:address => "smtpauth.dbmail.com",
                :domain => "dbmail.com",
                :port => 25,
                :user_name => "<EMAIL>",
                :password => "<PASSWORD>",
                :authentication => :login}

Mail.defaults do
  delivery_method :smtp, mail_options
end

def mail(invoices)
  body = Renderer::Hml.new.render('xero/report.html.haml', :invoices => invoices)
  mail = Mail.new do
    content_type 'text/html; charset=UTF-8'
    from '<EMAIL>'
    to "<EMAIL>"
    subject("#{invoices.size} new invoices in draft")
    body(body)
  end
  mail.deliver!
end

invoice(invoices)
mail(invoices)

{'fraction_non_alphanumeric': 0.15341138473960436, 'fraction_numerical': 0.0036334275333064193, 'mean_word_length': 3.588888888888889, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 32, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6051426', 'n_tokens_mistral': 870, 'n_tokens_neox': 841, 'n_words': 146}