Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
| Comment: | Fix sorting/ordering of transactions
Need to get things in the right order for checking whether we've gone far Also add appropriate Expenses/Income placeholder |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
5bdd7b804faa6dd65c5a79597e5b197d |
| User & Date: | atomicules 2015-07-04 13:36:15 |
|
2015-07-07
| ||
| 22:19 | Report out balance as a comment at end of the file check-in: 565270916f user: atomicules tags: trunk | |
|
2015-07-06
| ||
| 20:53 | Create new branch named "cascade_methods" check-in: cdb88b0318 user: atomicules tags: cascade_methods | |
| 20:32 | Create new branch named "pass_args" Closed-Leaf check-in: 7025864667 user: atomicules tags: pass_args | |
|
2015-07-04
| ||
| 13:36 |
Fix sorting/ordering of transactions
Need to get things in the right order for checking whether we've gone far Also add appropriate Expenses/Income placeholder check-in: 5bdd7b804f user: atomicules tags: trunk | |
| 11:21 |
Build it into a proper script
I'm not entirely sure whether a class structure is appropriate for this. At the - I'd got credits and debits the wrong way round | |
Changes to smile.rb.
| ︙ | ︙ | |||
89 90 91 92 93 94 95 |
#Previous statements
@page = @a.click(@page.link_with(:text => "previous statements"))
#Get first page of previous statements
@page = @a.click(@page.links_with(:href => %r{getDomestic} )[0])
date = Date.today
until date < @date_back
get_transactions
| > > | > | | | > > < > > | > > > | 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
#Previous statements
@page = @a.click(@page.link_with(:text => "previous statements"))
#Get first page of previous statements
@page = @a.click(@page.links_with(:href => %r{getDomestic} )[0])
date = Date.today
until date < @date_back
get_transactions
#On previous statement pages most recent transaction is at bottom
#This is opposite to recent item page
date = @transactions[-1][:date]
@page = @a.click(@page.link_with(:text => "previous statement page"))
end
end
def get_transactions
doc = Nokogiri::HTML(@page.body)
#Look for summaryTable
rows = doc.xpath("//table[@class='summaryTable']//tr")
#Skip first row (table headers, ths)
rows = rows[1..-1]
transactions = []
rows.each do |row|
#Skip last row, maybe
unless row.elements.length == 1
#Might as well parse date here
date = Date.parse(row.elements[0].text)
name = row.elements[1].text
credit = row.elements[2].text
debit = row.elements[3].text
unless name.include?("BROUGHT FORWARD")
transactions << { :date => date, :name => name, :credit => credit, :debit => debit}
end
end
end
#Sort in order of newest date first so can add on
@transactions += transactions.sort { | t1, t2 | t2[:date] <=> t1[:date] }
end
def write_ledger
File.open("smile.dat", "w") do |file|
#Reverse for writing out
@transactions.reverse!
@transactions.each do |transaction|
file << transaction[:date].strftime("%Y/%m/%d")+"\t"+transaction[:name]+"\n"
if transaction[:debit].include?("£")
amount = transaction[:debit].gsub(/£/, "£-")
type = "Expenses:"
else
amount = transaction[:credit]
type = "Income:"
end
file << "\t"+"Assets:Smile:Current"+"\t"+amount+"\n"
file << "\t"+type+"\n"
file << "\n"
end
end
end
private :logon_start
private :logon_passcode
|
| ︙ | ︙ |