Regex for custom price updater script

Thomas Baumgart thb at net-bembel.de
Sun Mar 6 13:57:07 GMT 2022


Hi,

regex are a fun thing to deal with. Here's what I came up with:

Price: (\d+(\.\d+)?)
Date: (\d{2}\/\d{2}\/\d{2})

The date did not work for you due to the extra spaces you have
included between '\' and '/' in the date regex. It was looking
for a space where there isn't any so it did not match.

Here's my version of prices.sh (for testing):

<quote>
#!/bin/bash

echo "18.7920"
echo "03/04/22"
</quote>

and the output resulting when I use that on a symbol named POS

<quote>
Executing /home/thb/prices.sh POS...
Identifier found: ''
Price found: '18.7920' (18,792)
Date found: 'Fr. März 4 2022'
Price for POS updated (id E000002)
</quote>

I am currently using this on master which I just modified to use QRegularExpression
instead of QRegExp a few days ago. Maybe that makes a difference. But running this
on 5.1 using QRegExp it provides the same results.

There's no need to check the 'skip HTML' as your output does not have any HTML.

Hope that gives you some ideas where to look.

Thomas



On Samstag, 5. März 2022 20:33:56 CET Louis-Philippe Allard via KMyMoney wrote:

> Hello,
> 
> I am using a local custom script to retrieve prices from the internet.
> 
> #!/bin/sh
> url=https://www.theglobeandmail.com/investing/markets/funds/
> curl -s "$url/$1"|
> ./pup -p 'a[is="barchart-alert"] attr{quote}'|
> jq -r .lastPrice,.tradeTime
> 
> Running this script in the Bash terminal with the fund symbol passed  
> as an argument will return something like:
> 
> /path/to/prices.sh SYMBOL
> 18.7920
> 03/04/22
> 
> However I cannot make KMM use this script.  I created a new source and  
> set the options as this:
> 
> URL:  file:/path/to/prices.sh %1
> Identifier %1
> Identify by: Symbol
> Price: (\d+(\.\d+)?)
> Date: (\d{2}\ /\d{2}\ /\d{2})
> Date format: %m/%d/%y
> Skip HTML... : CHECKED
> 
> When I run the price updater I get:
> 
>   Executing /path/to/prices.sh SYMBOL...
> 
>   Price found: '2.4' (2.4)
> 
>   Unable to update price for SYMBOL (no price or no date)
> 
> Problem 1:  it seems to retrieve the number of digits of the price  
> instead of the actual value...  I tried the price regex elsewhere and  
> it works.  Not sure if the Qt interpreter is causing this issue??
> Problem 2: I could never get the date... Tried pretty much everything  
> I could find but I am not sure why its not working.
> 
> Any help appreciated!
> Best regards
> 

-- 

Regards

Thomas Baumgart

https://www.signal.org/       Signal, the better WhatsApp
-------------------------------------------------------------
If Bill Gates put microchips in the vaccine, you would have
to go in for an update the second Tuesday of every month.
-------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 868 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kmymoney/attachments/20220306/47345aa4/attachment.sig>


More information about the KMyMoney mailing list