[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Getting currency rates
Hi Mike,
The code that Craig sent to Adam is even a little bit nicer. It uses
embedded SQL to build a PF and insert the exchange rates in that PF.
Perhaps Craig would be willing to post his code here?
But, yeah... the web site works nicely. Better than EXAMPLE18.
Mike Krebs wrote:
> Adam and anyone else interested in currency!
>
>>> GET /usd/feed HTTP/1.1
>>> Host: xurrency.com
>
> After seeing what you were trying to do
> (http://www.scottklement.com/archives/ftpapi/200807/msg00014.html), I just
> had to give it a go. Works good when you're not blocked by a firewall ;)
>
> Mike Krebs
>
> Here is the program adapted from example15 if anyone else wants to have a
> go. BTW, there is much more that is returned in the XML--view the source of
> http://xurrency.com/usd/feed to see other elements.
>
>
> H DFTACTGRP(*NO) BNDDIR('HTTPAPI')
>
>
>
> FQSYSPRT O F 132 PRINTER OFLIND(*INOF)
>
>
>
> /copy qrpglesrc,httpapi_h
>
> /copy qrpglesrc,ifsio_h
>
>
>
> D Incoming PR
>
> D userdata * value
>
> D depth 10I 0 value
>
> D name 1024A varying const
>
> D path 24576A varying const
>
> D value 65535A varying const
>
> D Attrs * dim(32767)
>
> D const options(*varsize)
>
>
>
> D num s 10I 0
>
> D item ds occurs(40)
>
> D title 512A varying
>
>
>
> D msg s 50A
>
> D rc s 10I 0
>
> D url s 100A varying
>
> D PrintLine s 132A
>
> D x s 10I 0
>
> D filename s 45A varying
>
>
>
> /free
>
>
>
> *inlr = *on;
>
>
>
> // ****************************************************
>
> // Download the latest exchange rates
>
> // ****************************************************
>
> url = 'http://xurrency.com/usd/feed';
>
> filename = http_tempfile() + '.xml';
>
>
>
> rc = http_url_get( url : filename );
>
> if (rc <> 1);
>
> PrintLine = http_error();
>
> except;
>
> unlink(filename);
>
> return;
>
> endif;
>
>
>
> // ****************************************************
>
> // parse the XML from the temp file.
>
> // ****************************************************
>
>
>
> if (http_parse_xml_stmf( filename
>
> : HTTP_XML_CALC
>
> : *null
>
> : %paddr(Incoming)
>
> : *null ) < 0 );
>
> PrintLine = http_error();
>
> except;
>
> unlink(filename);
>
> return;
>
> endif;
>
>
>
> // ****************************************************
>
> // Print the currency
>
> //
>
> // ****************************************************
>
>
>
> for x = 1 to num;
>
> %occur(item) = x;
>
> PrintLine = title;
>
> except;
>
> endfor;
>
>
>
> unlink(filename);
>
> return;
>
>
>
> /end-free
>
>
>
> OQSYSPRT E
>
> O PrintLine 132
>
>
>
>
>
> *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> * This is called for each XML element that's received in the
>
> * document.
>
> *
>
> *
>
> * The VALUE parameter gives us the text that's inside that
>
> * element.
>
> *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> P Incoming B
>
> D Incoming PI
>
> D userdata * value
>
> D depth 10I 0 value
>
> D name 1024A varying const
>
> D path 24576A varying const
>
> D value 65535A varying const
>
> D attrs * dim(32767)
>
> D const options(*varsize)
>
>
>
> D count s 10I 0
>
> D attrname s 100A varying
>
> D attrval s 100A varying
>
> /free
>
>
>
> select;
>
> when name = 'dc:simpleTitle';
>
> num = num + 1;
>
> %occur(item) = num;
>
> title = value;
>
> endsl;
>
>
>
> /end-free
>
> P E
>
> And the output:
>
> 1 USD = 0.6389 EUR
> 1 USD = 0.5088 GBP
> 1 USD = 1.0455 AUD
> 1 USD = 1.6000 BRL
> 1 USD = 1.3278 NZD
> 1 USD = 1.0216 CAD
> 1 USD = 1.0318 CHF
> 1 USD = 6.8681 CNY
> 1 USD = 4.7642 DKK
> 1 USD = 7.8003 HKD
> 1 USD = 43.2900 INR
> 1 USD = 107.5269 JPY
> 1 USD = 1000.0000 KRW
> 1 USD = 107.5269 LKR
> 1 USD = 10.3199 MXN
> 1 USD = 3.2658 MYR
> 1 USD = 5.1020 NOK
> 1 USD = 6.0096 SEK
> 1 USD = 1.3643 SGD
> 1 USD = 33.6700 THB
> 1 USD = 30.3951 TWD
> 1 USD = 2.1445 VEF
> 1 USD = 7.7459 ZAR
> 1 USD = 1.2497 BGN
> 1 USD = 15.0376 CZK
> 1 USD = 10.0000 EEK
> 1 USD = 149.2537 HUF
> 1 USD = 2.2060 LTL
> 1 USD = 0.4497 LVL
> 1 USD = 2.1155 PLN
> 1 USD = 2.3020 RON
> 1 USD = 19.3424 SKK
> 1 USD = 4.6275 ISK
> 1 USD = 76.9231 HRK
> 1 USD = 23.5294 RUB
> 1 USD = 1.2284 TRY
> 1 USD = 45.6621 PHP
> 1 USD = 2000.0000 COP
> 1 USD = 3.1646 ARS
>
> -----------------------------------------------------------------------
> This is the FTPAPI mailing list. To unsubscribe, please go to:
> http://www.scottklement.com/mailman/listinfo/ftpapi
> -----------------------------------------------------------------------
>
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------