Smile Bank to Ledger

Check-in [e176864222]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix for negative balances

Sob. Sob. Not that I ever want to see them though.

I'd inadvertently assumed I'd only ever see a positive balance. Need to regexp
to get the negative that Smile put at the end of the balance and stick that in
the right balance, but only if a negative - it seems Ledger doesn't understand
a plus sign in front of numbers.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e176864222a3cf5a1d44ab1ba7b99bc20b17c308
User & Date: atomicules 2016-01-06 13:27:07
Context
2016-09-04
14:15
Last tweaks I'd made. Commit for reference

I'd forgotten to commit these. Committing for reference since none of this
works anymore. Only option is to use a webbrowser and download the csv. Will be
changing this into a CSV parser. Maybe. Might even just do that in Vim. check-in: ce95ff0dde user: atomicules tags: old-smile-site, trunk

2016-01-06
13:27
Fix for negative balances

Sob. Sob. Not that I ever want to see them though.

I'd inadvertently assumed I'd only ever see a positive balance. Need to regexp
to get the negative that Smile put at the end of the balance and stick that in
the right balance, but only if a negative - it seems Ledger doesn't understand
a plus sign in front of numbers. check-in: e176864222 user: atomicules tags: trunk

2015-10-19
21:33
Ensure all extraneous spaces are removed check-in: cf683f4151 user: atomicules tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to smile.rb.

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

	def recent_transactions
		#requires
		page = logon_bulletin
		page = @a.click(page.link_with(:text => "current account"))
		get_transactions(page)
		doc = Nokogiri::HTML(page.body)
		#Remove any trailing plus and minus on actual balance so can use as balance assertion
		@balance = doc.xpath("//td[@class='recentTransactionsAccountData']/table/tr[2]/td[2]").text.strip.gsub(/\+|\-/, "")
		@available = doc.xpath("//td[@class='recentTransactionsAccountData']/table/tr[3]/td[2]").text.strip
		#Need to return this
		page
	end


	def previous_statements







|
|







80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

	def recent_transactions
		#requires
		page = logon_bulletin
		page = @a.click(page.link_with(:text => "current account"))
		get_transactions(page)
		doc = Nokogiri::HTML(page.body)
		#Any trailiing minus needs to be moved to before the number, but any trailing plus needs to be removed, don't think this can be done in one gsub.
		@balance = doc.xpath("//td[@class='recentTransactionsAccountData']/table/tr[2]/td[2]").text.strip.gsub(/(£)(\d+\.\d+)(\-)/, "\\1\\3\\2").gsub(/\+/, "")
		@available = doc.xpath("//td[@class='recentTransactionsAccountData']/table/tr[3]/td[2]").text.strip
		#Need to return this
		page
	end


	def previous_statements
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154

155
156
157
158
159
160
161
		balance_assertion = ""
		File.open("smile.dat", "w") do |file|
			#Reverse for writing out
			@transactions.reverse!
			@transactions.each.with_index do |transaction, idx|
				file << transaction[:date].strftime("%Y/%m/%d")+"\t*\t"+transaction[:name]+"\n"
				if transaction[:debit].include?("£")

					amount = transaction[:debit].gsub(/£/, "£-")
					type = "Expenses:"
				else
					amount = transaction[:credit]
					type = "Income:"
				end
				if idx == @transactions.length-1
					#Include balance assertion at the end.
					balance_assertion = "\t= "+@balance

				end
				file << "\t"+"Assets:Smile:Current"+"\t"+amount+balance_assertion+"\n"
				file << "\t"+type+"\n"
				file << "\n"
			end
			#Write out account balance as a comment at the end
			file << "#Available: "+@available+"\n"







>
|


|





>







139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
		balance_assertion = ""
		File.open("smile.dat", "w") do |file|
			#Reverse for writing out
			@transactions.reverse!
			@transactions.each.with_index do |transaction, idx|
				file << transaction[:date].strftime("%Y/%m/%d")+"\t*\t"+transaction[:name]+"\n"
				if transaction[:debit].include?("£")
					#Quote all commodities because having ledger utf-8 trouble
					amount = transaction[:debit].gsub(/£/, "\"£\"-")
					type = "Expenses:"
				else
					amount = transaction[:credit].gsub(/£/, "\"£\"")
					type = "Income:"
				end
				if idx == @transactions.length-1
					#Include balance assertion at the end.
					balance_assertion = "\t= "+@balance
					balance_assertion = balance_assertion.gsub(/£/, "\"£\"")
				end
				file << "\t"+"Assets:Smile:Current"+"\t"+amount+balance_assertion+"\n"
				file << "\t"+type+"\n"
				file << "\n"
			end
			#Write out account balance as a comment at the end
			file << "#Available: "+@available+"\n"