Friday, August 28, 2009

GnuCash can't get currency quotes

I have just installed GnuCash and like it immensely. However when I tried to get a currency quote all I got was:
unable to retrieve quotes CURRENCY:USD
Not too useful! It has taken me a while to track down the problem even with Google, so I thought I would give a simple quick fix here. This quick fix is followed by a fuller description of the problem.

Locate the file on your computer. On my Mac it is in /Library/Perl/5.8.8/Finance. You must replace it with this version of

GnuCash will now be able to get currencies properly. You can test it with:
bin $ ./gnc-fq-dump currency USD EUR
1 USD = 0.6963 EUR
bin $ ./gnc-fq-dump currency EUR USD
1 EUR = 1.4362 USD
Note: It is not a good idea to trust code files from the web so you should really do a diff on your file and the new one before installing it. That way you can see that there is no malicious code there. If you do a diff command you should see something like the following. If you see extra code or are worried about what you see do not install it.

bash-3.2# diff -w -u
--- 2009-04-13 16:15:29.000000000 +0200
+++ 2009-08-28 15:42:25.000000000 +0200
@@ -1,5 +1,11 @@
#!/usr/bin/perl -w
+# Warning: This file has been edited to fix currencies not working because
+# the Yahoo page has changed. You should keep an eye out for an official
+# fix and use that when it comes out. This file may cause future problems
+# keep the old one available.
# Copyright (C) 1998, Dj Padzensky
# Copyright (C) 1998, 1999 Linas Vepstas
# Copyright (C) 2000, Yannick LE NY
@@ -36,15 +42,17 @@
use Finance::Quote::UserAgent;
use HTTP::Request::Common;
use HTML::TableExtract;
+use Finance::Quote::Yahoo::Base qw/yahoo_request/;
use Encode;
# If the above URL ever fails, try rewriting this module to use the URL below.
@ISA = qw/Exporter/;
@EXPORT = ();
@@ -239,18 +247,13 @@
return $amount if ($from eq $to); # Trivial case.
- my $ua = $this->user_agent;
- my $data = $ua->request(GET "${YAHOO_CURRENCY_URL}from=$from&to=$to")->content;
- my $te = HTML::TableExtract->new( headers => ['Symbol', 'Bid', 'Ask'] );
- $te->parse(decode_utf8($data)); # The web page returns utf8 content which gives
- # a warning when parsing $data in HTML::Parser
+ my $symbol = "$from$to=X";
+ my @symbols = ($symbol);
+ my %info = yahoo_request($this,$YAHOO_CURRENCY_URL,\@symbols);
+ return undef unless $info{$symbol,"success"};
- # Make sure there's a table to parse.
- return undef unless ($te->tables);
+ my $exchange_rate = $info{$symbol,"last"};
- my $row = ($te->rows())[0];
- my ($exchange_rate) = $$row[1];
$exchange_rate =~ s/,// ; # solve a bug when conversion rate
# involves thousands. yahoo inserts
# a comma when thousands occur

It turns out to be a problem in the Perl Finance::Quote module because Yahoo have changed the way they have done their currency web page; that's the problem with page scraping. Anyway, I finally found a patch for the problem here but it did not work out of the box because I have the latest version of Finance::Quote and it was incompatible. So, after hand editing it I thought that I would make a patched of Finance::Quote version 1.16 available above.

Keep an eye on the official version and switch to that when it is released.

Happy Accounting!

Saturday, March 21, 2009

Disabling ssh password access

I am going away for a few days and have decided that I want to be able to access my main machine from my laptop. I normally use ssh for logging in from one machine to another and normally use private keys for all my ssh connections but do have password access available as well. However, this time, as I plan to leave TCP port 22 (the ssh port) open through my home router to my iMac and I want it to be as secure as possible. This means that I do not want password access at all, only private keys.

So, I have edited the /etc/sshd_config (or /etc/ssh/sshd_config) file to include the lines:

PasswordAuthentication no
UsePAM no

These lines turn password access off and force ssh to require the use of a private key. If you don't have a key that allows login then login is immediately rejected. I feel pretty secure as far as ssh is concerned now.

I just have to remember to copy the public key from my laptop to my iMac before I leave!

Tuesday, March 10, 2009

Opening Tabs in Safari 4

I've downloaded and have been using the new Safari 4 beta. It's great, I love the new tabs and the fact that I can drag them in and out of windows (using the little triangular icon in the top right of the tab) makes them very manageable. I've even given up using Camino, I'm very happy with the new version.

I'm still getting used to the tabs being at the top rather than under the address bar. I could change it, however it does make sense because the address bar belongs to the tab, so it should be included inside the tab. Another example of Apple doing things properly.

Ok, I have one slight problem, when I click on a link in GMail or Reddit I get a new window opened rather a new tab in the same window. The preferences don't help, they only have "open a new tab in the same window if a link is clicked on by an application like Mail or iTunes etc." The fix? Open a terminal window and enter the following at the prompt (this is one single line, it may have been broken into two by your browser):

defaults write TargetedClicksCreateTabs -bool true

Thereafter, Safari will preferentially open a new tab in the current window instead of a new window. This will not affect the normal links that replace the current page, they will still work in the same way. Give it a try, if you don't like it you can undo the action with:

defaults write TargetedClicksCreateTabs -bool false

As an extra, if you really don't like the tabs being above the address bar and want them in the old place then you can again use a terminal window and enter:

defaults write DebugSafari4TabBarIsOnTop -bool false