[GNC] AutoHotKey: Date Arithmetic Example
Geoff
cleanoutmyshed at gmail.com
Sun Aug 14 21:44:21 EDT 2022
Hi Tom
Yes, AutoHotKey is quite a powerful scripting language and has some
basic date handling functionality built in. Here is a trivial example
as a demonstration, but note that it fails for cases where the day of
the month is greater than 28. This is easy to fix, but I don't know the
specific rules imposed by your bank.
See attached screenshot before reading any further.
=====
Loop, 12 {
start_date := 2022 . SubStr(0 . A_Index, -1, 2) . 15
month := SubStr(start_date, 5, 2) - 16
prior_date := SubStr(start_date, 1, 4)
+ floor((month - 1) / 12)
. SubStr(0 . (month < 0
? mod(month, 12) + 12
: mod(month - 1, 12) + 1)
, -1 ,2)
. SubStr(start_date, 7)
FormatTime, show_start, %start_date%, ddd dd-MMM-yyyy
FormatTime, show_prior, %prior_date%, ddd dd-MMM-yyyy
results := results
. "Start: " . show_start
. "`nPrior: " . show_prior
. "`n`n"
}
MsgBox,, AutoHotKey: Subtract 16 Months Example for Tom, %results%
=====
The syntax is a bit quirky at first, but the documentation is good and
if you can drive Raku you can certainly drive AHK ;--)
HOWEVER, as it seems that you are bank scraping, you should consider
Selenium which is a very useful and extremely powerful tool for web
browser automation: https://www.selenium.dev/, *plus* it can be driven
from a variety of languages including Python, Perl, and (according to
Google) Raku:
https://raku.land/github:azawawi/Selenium::WebDriver
Hope this helps.
Regards
Geoff
=====
On 15/08/2022 12:50 am, Tom Browder wrote:
> On Sun, Aug 14, 2022 at 00:40 Geoff <cleanoutmyshed at gmail.com
> <mailto:cleanoutmyshed at gmail.com>> wrote:
>
> Hi Jim
>
> I don't have any experience manipulating GnuCash XML files, but in
> principle what you want to do should work, although it does void your
> GnuCash warranty.
>
> However, if you are going to all this effort you may find it more
> worthwhile to invest your time in learning how to use a general purpose
> automation tool. This approach has two advantages over data
> manipulation:
> (1) Automation drives the GnuCash GUI and thus protects you from
> accidental data corruption.
> (2) You will be able to use your new automation skills to automate any
> subsequent GnuCash tasks, for example loading historical
> transactions to
> your 130 securities.
>
> For Windows, check out:
> AutoHotKey https://www.autohotkey.com/ <https://www.autohotkey.com/>
>
>
> Geoff, that looks very interesting, thanks for the link. I do most of my
> work on Linux, but I do have to do some things on Windows (TL;DR), so
> this is very useful.
>
> One of the things I'm not sure about is how powerful the script is. For
> instance, can it determine the date for 16 months before the current
> date? That's one of the requirements for one of my banks earliest date
> of data retrieval. And one has to start over again for each different
> account.
>
> If it can't, then I will use the power of Raku to regenerate the
> autohotkey script for the current date.
>
> Best regards,
>
> -Tom
>
> P.S. Is there a spot on the Wiki to list things like Geoff's suggestion
> and flycatcher's program? If not, I will be glad to start
> one--suggestions welcomed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gnc_ahk_subtract_16_months.jpg
Type: image/jpeg
Size: 73854 bytes
Desc: not available
URL: <http://lists.gnucash.org/pipermail/gnucash-user/attachments/20220815/442f80eb/attachment-0001.jpg>
-------------- next part --------------
Loop, 12 {
start_date := 2022 . SubStr(0 . A_Index, -1 ,2) . 15
month := SubStr(start_date, 5, 2) - 16
prior_date := SubStr(start_date, 1, 4)
+ floor((month - 1) / 12)
. SubStr(0 . (month < 0
? mod(month, 12) + 12
: mod(month - 1, 12) + 1)
, -1 ,2)
. SubStr(start_date, 7)
FormatTime, show_start, %start_date%, ddd dd-MMM-yyyy
FormatTime, show_prior, %prior_date%, ddd dd-MMM-yyyy
results := results
. "Start: " . show_start
. "`nPrior: " . show_prior
. "`n`n"
}
MsgBox,, AutoHotKey: Subtract 16 Months Example for Tom, %results%
More information about the gnucash-user
mailing list