Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

The idea is to download a zipped file from a website and unzip it using FME 2011. I have attached a screenshot of FME workbench which is not working. Any help is greatly appreciated.

Thanks.

Sam

FME Workbench

share|improve this question
1  
It may be helpful if you posted the unobscured error from the log. –  Raven Sep 2 '11 at 18:30
add comment

2 Answers 2

Your code seems incorrect. Try:

import pyfme, os, zipfile
z = zipfile.ZipFile("GoTransitDL.zip")
z.extractall()

And just as a warning (from API docs):

Warning Never extract archives from untrusted sources without prior inspection. It is possible that files are created outside of path, e.g. members that have absolute filenames starting with "/" or filenames with two dots "..".

The zip file can be made to extract files to anywhere on your hard drive, and z.extractall() will oblige. Very dangerous if you don't know the source.

share|improve this answer
    
Thanks Sasa. I changed the code as you suggested but it gave me the same error. I am wondering if the parameters that I set are creating errors. Also is there a safer way to download and unzip files from a website using FME? –  Sam Aug 25 '11 at 18:37
    
Tend to download the files first and have the virus scanner run through them first before extracting - would be good if FME could run the virus scanner as part of the process. –  Mapperz Aug 25 '11 at 20:27
    
Sam, make sure your import is using the correct case - your code imports ZipFile rather than zipfile. Based on what I can see of the FME log it appears a module isn't being found. –  Raven Sep 2 '11 at 18:33
add comment

I just did the exact same thing. You should check the documentation on the PythonCaller. You need to create a function or class as described in the help. Use a function to process a single feature, as in this case.

Example:

from zipfile import ZipFile

def fmeUnzip(fmeFeature):
    zipFile = fmeFeature.getAttribute("_ZIPFILE_NAME")
    outDir = fmeFeature.getAttribute("_OUTPUT_DIR")
    unzip(zipFile, outDir)

def unzip(zipFile, outDir):
    z = ZipFile(zipFile)
    z.extractall(outDir)

In the PythonCaller parameters, set 'Symbol to use' to fmeUnzip and copy the code to the source code parameter. You can alternatively save it in a .py file, see the PythonCaller help for how to do this.

Note: _ZIPFILE_NAME and _OUTPUT_DIR are attributes created by ParameterFetcher transformers, which create attributes based on the values of workspace parameters.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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