MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Problem with Import and/or J/Link

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65013] Re: [mg64958] Re: Problem with Import and/or J/Link
  • From: Todd Gayley <tgayley at wolfram.com>
  • Date: Sat, 11 Mar 2006 05:15:55 -0500 (EST)
  • References: <dubho4$fuq$1@smc.vnet.net> <due8p9$a71$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

At 04:14 AM 3/10/2006, John Jowett wrote:
>Brian,
>
>Thanks but, no, that didn't work. The strange thing is that the GetURL
>example notebook for J/Link works. I believe this is an older
>implementation, before the functionality was included in Import.
>
>So, I'm still looking for an answer, if anyone has an idea. I have also
>asked Wolfram support who have made some suggestions but not solved the
>problem yet.


John,

This is a bug in Import. Import uses the Utilities`URLTools`FetchURL 
function to download the content from the given URL. FetchURL tries to 
choose an appropriate local file name for the URL content based on the URL 
itself, and this code gets confused by the complex query string in that 
URL. FetchURL also lets you pass in a filename to use, however, and that is 
how Import should be calling it (after all, the file is deleted by Import 
after it is read, so it's not important for it to have a meaningful name).

The solution is to call FetchURL directly, supplying the name of a 
temporary file to use, so it doesn't have to try to come up with one based 
on the URL. You also want to delete the file after it is read. Calling 
Close[OpenTemporary[]] is a standard trick for getting the full path to a 
temporary file:

HttpImport[url_String, format_String] :=
     Module[{tempFile, result},
         tempFile = Utilities`URLTools`FetchURL[url, Close[OpenTemporary[]]];
         result = Import[tempFile, format];
         DeleteFile[tempFile];
         result
     ]

This new function works on your complex URL:

HttpImport["http://ichart.finance.yahoo.com/table.csv?s=%5EDJI&a=09&b=1&c=2000&d=01&e=9&f=2006&g=m&ignore=.csv";, 
"CSV"]


Todd Gayley
Wolfram Research



><bghiggins at ucdavis.edu> wrote in message news:due8p9$a71$1 at smc.vnet.net...
>
> > John,
> > I do not have a Window's machine available at this time. I did try
> > Import with the URL ("/http://ichart.finance...."; on my Mac OS X4.5
> > with V5.2 and it works.
> >
> > The error message suggests that there might be a character(s) in the
> > URL that needs to be escaped on a Windows machine
> >
> > Try the simple version of your URL:
> >
> > Import["http://ichart.finance.yahoo.com/table.csv?s=%5EDJI";, "CSV"]
> >
> > and see if that works. On my Mac I get
> >
> > {{"Date", "Open", "High", "Low", "Close", "Volume", "Adj. Close*"},
> >   {"3-Mar-06", 11024.23, 11125.01, 10942.99, 11021.59, 2152950016,
> > 11021.59},
> >   {"2-Mar-06", 11052.57, 11090.91, 10951.71, 11025.51, 2494589952,
> > 11025.51}}
> >
> > Cheers,
> >
> > Brian
> >


  • Prev by Date: Re: Mathematica and Education
  • Next by Date: Total Derivative and Output Display Question
  • Previous by thread: Re: Problem with Import and/or J/Link
  • Next by thread: FindInstance for sudoku