David here, from the Zapier Platform team.
Your code as written doesn't work because the first argument for the open
function is the filepath. There's no file at the path 'file'
, so you'll get an error. You access the input via the input_data
dictionary.
That being said, the input is a url, not a file. You need to use urllib
to read that url. I found the answer here.
I've got a working copy of the code like so:
import urllib # the lib that handles the url stuff
result = []
data = urllib.request.urlopen(input_data['file'])
for line in data: # file lines are iterable
result.append(line) # keep each line, or parse, etc.
return {'lines': result}
The key takeaway is that you need to return a dictionary from the function, so make sure you somehow squish your file into one.
Let me know if you've got any other questions!