I have looked through the documentation and don't see this addressed, but since some of you seem to have knowledge of undocumented features, I thought I'd ask. There is a zip file at http://www.retrosheet.org/gamelogs/gl2015.zip. It extracts to a single file, GL2015.TXT (even though it's a CSV).

I want to get this into a Dataset. If I unzip the file and place it on my hard drive somewhere then this works (where retfor is a list containing the types of each column in the dataset):

gl15 = SemanticImport["/GL2015.TXT", retfor, "Dataset"]

I'd like to be able to read the zip file directly from the website and not download and extract it to my hard drive. With Import you can use the following:

gl15 = Import["http://www.retrosheet.org/gamelogs/gl2015.zip","*"]

Any ideas?

  • 1
    $\begingroup$ You can build such a function by combining Import, ExtractArchive, DeleteFile (to remove the zip file) and SemanticImport, is that ok or is that what you are trying to avoid? $\endgroup$ – C. E. May 8 '16 at 13:13
  • $\begingroup$ Yes, currently I'm using URLSave, ExtractArchive,SemanticImport and DeleteFile but it seems kludgy. $\endgroup$ – G. Pelkabo May 8 '16 at 14:09

If you don't want to save the file to the disk, you can use stream to do the trick. You can import the zip file as a string from the web and convert it to stream, which then can be treated as a file.

For example:

str=Import[url, "String"];
filename = First@Import[StringToStream[str], "ZIP"];

SemanticImportString[Import[StringToStream[str],{"ZIP", filename, "String"}]]
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.