[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Getting currency rates
Unfortunately, the admins and managers are refusing to change
anything, so I just cannot take this any further. I thank you all for
your help and hopefully others have benefited.
I now need to look at an older way of doing this via FTP.
--- On Wed, 7/9/08, Craig Jacobsen <CJacobsen@xxxxxxxxxxxxx> wrote:
From: Craig Jacobsen <CJacobsen@xxxxxxxxxxxxx>
Subject: RE: Getting currency rates
To: "HTTPAPI and FTPAPI Projects" <ftpapi@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wednesday, July 9, 2008, 11:31 AM
Sure no problem Scott, here it is (with your changes included)
SQLRPGLE (file will be in qTemp/USDConv columns will be Country
(abbreviation) and Rate (to 1 USD):
H BndDir('HTTPAPI') ActGrp(*New) DftActGrp(*No)
H Option(*SrcStmt:*NoDebugIO) Debug(*Yes)
D RetCode s 10I 0
D Url s 100A varying
D UrlRedirect s 100A varying
D Country s 10A
D Rate s 11p 3
D FileName s 45A varying
/include qrpglesrc,httpapi_h
/include qrpglesrc,ifsio_h
D Incoming PR
D UserData * Value
D Depth 10I 0 Value
D namespace 1024a varying const
D Name 1024A Varying Const
D Path 24576A Varying Const
D Value 65535A Varying Const
D Attrs * Dim(32767)
D Const Options(*VarSize)
/Free
*InLR = *On;
// debug (ifs subdir tmp/httpapi_debug.txt if on)
Http_Debug(*Off);
// set sql defaults
Exec SQL
Set Option
Naming = *Sys,
Commit = *None,
UsrPrf = *User,
DynUsrPrf = *User,
Datfmt = *iso,
CloSqlCsr = *EndMod;
// create the table (if not already there)
Exec SQL
Create Table qTemp/USDConv
(Country Char(10),
Rate Decimal(11, 3));
// delete all records
Exec SQL
Delete From qTemp/USDConv;
// URL to get currency conversion, always USD to other country
Url = 'http://xurrency.com/usd/feed';
// create a tempory file in subdirectory tmp in the ifs
FileName = Http_TempFile() + '.xml';
// get the currency
RetCode = Http_Url_Get(Url : FileName );
// If errors, leave the temp file and crash the program
If RetCode <> 1;
Http_Crash();
Return;
EndIf;
// Parse the XML from the temp file
http_xmlns(*ON);
If Http_Parse_XML_Stmf( FileName
: HTTP_XML_CALC
: *Null
: %PAddr(Incoming)
: *Null )
< 0;
EndIf;
// delete the work file
UnLink(FileName);
// that's all
Return;
/End-Free
P Incoming B
D Incoming PI
D UserData * Value
D Depth 10I 0 Value
D NameSpace 1024A Varying Const
D Name 1024A Varying Const
D Path 24576A Varying Const
D Value 65535A Varying Const
D Attrs * Dim(32767)
D Const Options(*VarSize)
D DC C 'http://purl.org/dc/-
D elements/1.1/'
D AttrName s 100A Varying
D AttrVal s 100A Varying
/free
If Path = '/RDF/item';
If NameSpace=DC and Name = 'targetCurrency';
Country = Value;
ElseIf NameSpace=DC and Name = 'value';
monitor;
Rate = %dec(Value:11:3);
on-error;
Rate = 0;
endmon;
Exec SQL Insert INTO qTemp/USDConv Values(ucase(:Country), :Rate);
EndIf;
EndIf;
/end-free
P E
-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
[mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Scott
Klement
Sent: Tuesday, July 08, 2008 5:50 PM
To: HTTPAPI and FTPAPI Projects
Subject: 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
-----------------------------------------------------------------------
Confidentiality Notice: This e-mail message, including any attachments, is for
the sole use of the intended recipient(s) and may contain confidential and
privileged information. Any unauthorized review, use, disclosure or
distribution is prohibited. If you are not the intended recipient, please
contact the sender by reply e-mail and destroy all copies of the original
message. Unless expressly stated in this e-mail, nothing in this message or
any attachment should be construed as a digital or electronic signature.
-----------------------------------------------------------------------
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
-----------------------------------------------------------------------