Reply to topic

Currency exchange rates

User avatar JesusM
Registered Member
Posts
134
Karma
0
OS

Currency exchange rates

Sat Sep 07, 2019 10:55 am
Hi there!

Over my time using Skrooge I've been using different addons to download the currency exchange rates, and one after other they eventually stopped working. Lately I've been using "Grandtrunk", and the thing it still works to the extent that the URL works and you get some results ... but the values are not updated since last Sept/1st.

For funds and pension plans I wrote my own tiny addon (by the way, I could publish it if you think it is useful, although it is mainly for Spanish products), but even when I try, I could not find a way to write a new addon for currency exchange. And cannot get any of the included ones working.

Any idea? Anyone can give me a hand?

EDIT: some code to get currency exchanges (but it doesn't work)

perl script:
Code: Select all
#!/usr/bin/perl

my $EXdate;
my $EXprice;

my $EXid = shift @ARGV;
my ($CURfrom, $CURto) = split /\//, $EXid;
my $web="curl -s -C - https://api.ratesapi.io/api/latest?base=$CURfrom\\\&symbols=$CURto";

foreach my $linea (`$web`) {
  $linea =~ s/\n//g;

  ( $EXprice, $EXdate ) = ( $linea =~ /\"$CURto\"\:([0-9\.]+)\}.*\"date\"\:\"([0-9\-]+)\"/ ) ;

  printf "%s_%s\n", $EXdate, $EXprice;
}


an execution example (apparently it works fine):
[email protected]:/usr/share/skrooge/quotes# RateAPI.pl JPY/EUR
2019-09-06_0.0084738581


and then the TXT addon:
Code: Select all
script=RateAPI.pl %1
mode=CSV
date=^(\d+-\d+-\d+)_
price=_([0-9\.\,]+)$
dateformat=yyyy-MM-dd


But when I try to run it from Skrooge I get nothing at all. No errors but the commodity is not updated.

What am I doing wrong?

Thanks!
Jesus M Diaz
User avatar smankowski
Moderator
Posts
966
Karma
7
OS

Re: Currency exchange rates  Topic is solved

Wed Sep 11, 2019 10:41 am
Hi,
Thanks to your post, I delivered OFFICIALLY a new source using ratesapi.io.
Here is the commit: https://cgit.kde.org/skrooge.git/commit ... c217f781a0

Regards.


Skrooge, a personal finances manager powered by KDE
Image
User avatar JesusM
Registered Member
Posts
134
Karma
0
OS

Re: Currency exchange rates

Wed Sep 11, 2019 7:01 pm
Hi,

thanks, but I am getting an error, and when I run the script manually:
Code: Select all
[email protected]:/usr/share/skrooge# /usr/share/skrooge/skrooge-ratesapi.py EUR/JPY
Traceback (most recent call last):
  File "/usr/share/skrooge/skrooge-ratesapi.py", line 27, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

Maybe there is a library not included?

On the other hand, to understand why my script didn't work ... only Python scripts work?

//JM
User avatar smankowski
Moderator
Posts
966
Karma
7
OS

Re: Currency exchange rates

Wed Sep 11, 2019 7:06 pm
JesusM wrote:Hi,

thanks, but I am getting an error, and when I run the script manually:
Code: Select all
[email protected]:/usr/share/skrooge# /usr/share/skrooge/skrooge-ratesapi.py EUR/JPY
Traceback (most recent call last):
  File "/usr/share/skrooge/skrooge-ratesapi.py", line 27, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

Maybe there is a library not included?

Yes, you need to install "requests"
JesusM wrote:
On the other hand, to understand why my script didn't work ... only Python scripts work?

No, but your script doesn't return csv.
The output must be something like this:
Code: Select all
Date,Price
2019-09-11,1.1003

JesusM wrote:
//JM


Skrooge, a personal finances manager powered by KDE
Image
User avatar JesusM
Registered Member
Posts
134
Karma
0
OS

Re: Currency exchange rates

Wed Sep 11, 2019 8:02 pm
smankowski wrote:Yes, you need to install "requests"

Done and working, thanks.

smankowski wrote:No, but your script doesn't return csv.
The output must be something like this:
Code: Select all
Date,Price
2019-09-11,1.1003



I thought it was enough if the regex at the TXT file matched the output. I have changed it now to your sample and it's working fine. Thanks once again.

//JM

 
Reply to topic

Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Invictus