Regex for custom price updater script

Louis-Philippe Allard lp.allard.1 at gmail.com
Sun Mar 6 15:36:16 GMT 2022


  Hallo Thomas,

Not sure what I'm doing wrong, but I cannot make it work...  If I  
manually run the "script" in terminal, it outputs the RAW values for  
price and date on 2 separate lines (-r arg of jq outputs RAW data).

user at vm:/mnt/local$ /mnt/local/prices.sh CIG2111.CF
10.2830
03/04/22

which is (AFAIK) identical to simply echoing the price and date as you  
did....  Somehow, KMM can retrieve the price and date just fine when I  
echo their values but when I use the script with "jq" command, kmm  
complains

Executing /mnt/local/prices.sh CIG2111.CF...

  Price found: '2.4' (2.4)

  Unable to update price for CIG2111.CF (no price or no date)

  My parameters:

Price regex: (\d+(\.\d+)?)
Date regex: (\d{2}\/\d{2}\/\d{2}) (i removed the spaces....sorry)
Date format: %m/%d/%y
Skip HTML: UNCHECKED

When running KMM from CLI, I do see this in the terminal (if relevant):

kmymoney_webpricequote: quotedata "curl:  
/tmp/.mount_kmymonXfrMyZ/usr/lib/liblber-2.4.so.2: no version  
information available (required by  
/lib/x86_64-linux-gnu/libcurl.so.4)\ncurl:  
/tmp/.mount_kmymonXfrMyZ/usr/lib/libldap_r-2.4.so.2: no version  
information available (required by  
/lib/x86_64-linux-gnu/libcurl.so.4)\n"
kmymoney_webpricequote: stripped text "curl:  
/tmp/.mount_kmymonXfrMyZ/usr/lib/liblber-2.4.so.2: no version  
information available (required by /lib/x86_64-linux-gnu/libcurl.so.4)  
curl: /tmp/.mount_kmymonXfrMyZ/usr/lib/libldap_r-2.4.so.2: no version  
information available (required by /lib/x86_64-linux-gnu/libcurl.so.4)"
kmymoney_webpricequote: Price "2.4"
qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 12168,  
resource id: 20859890, major code: 40 (TranslateCoords), minor code: 0

Somehow I think the output of my script is giving a hard time to KMM.  
I AM TESTING WITH 5.1.2-DCB4EF208 (KMYMONEY-5.1-40-LINUX-CENTOS_64-GCC)

  Looking forward to seeing what you think of that!

Thanks!

Quoting Thomas Baumgart via KMyMoney <kmymoney at kde.org>:

> 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.-------------------------------------------------------------
  Louis-Philippe Allard
lp.allard.1 at gmail.com
Sent using Horde Groupware on GNU/Linux
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kmymoney/attachments/20220306/ce7d8c4c/attachment.htm>


More information about the KMyMoney mailing list