xilopaint Posted June 23, 2016 Posted June 23, 2016 (edited) I am a beginner on coding and made a simple Python workflow but wasn't able to perform multiple script filter results at once. EDIT: Code removed. Edited January 4, 2020 by xilopaint
deanishe Posted June 23, 2016 Posted June 23, 2016 If you want to add multiple results, just call wf.add_item() multiple times.It's important to note that when you call wf.send_feedback() the workflow is finished as far as Alfred is concerned. You cannot send more results after that.You also don't need all that urllib/urllib2/json crap. Alfred-Workflow has its own much more pleasant-to-use HTTP library (modelled on requests): from workflow import web r = web.get('http://receitaws.com.br/v1/cnpj/' + query) r.raise_for_status() # Throw an exception if the web request failed data = r.json() output = data['nome'] … …
xilopaint Posted June 24, 2016 Author Posted June 24, 2016 (edited) Thank you deanishe! In fact on my attempts I called wf.send_feedback() for every wf.add_item(). That was the reason I've got just one result. Besides that, could you offer an explanation for dummies on how r.raise_for_status() works? Thanks again! Edited June 24, 2016 by xilopaint
deanishe Posted June 24, 2016 Posted June 24, 2016 Thank you deanishe! In fact on my attempts I called wf.send_feedback() for every wf.add_item(). That was the reason I've got just one result. Besides that, could you offer a explanation for dummies on how r.raise_for_status() works? Thanks again! If a web request fails (no Internet connection, server error, file not found etc. etc.), instead of exploding immediately, web.py stores the error on the Response object. raise_for_status() simply re-raises the stored error if there is one. This is normally the behaviour you want (if the request failed, you have no data). But you might be doing something else, like checking a bunch of URLs to ensure they're valid (i.e. not 404). In that case, you don't care whether the request succeeded or not, you just need the HTTP status code. The reason for implementing it this way is simply because that's what requests does, and web.py is basically a very lightweight clone of requests to cover the most common use cases without adding megabytes to the size of your workflow (requests is a big library). The idea is that you can replace web.py pretty easily with requests if you need a more full-featured HTTP library. Thanks for the beer money! I'll spend that tonight on drowning my sorrows now my idiot countryfolk have voted to leave the EU and screwed me royally xilopaint 1
xilopaint Posted June 29, 2016 Author Posted June 29, 2016 (edited) Hey deanishe, the workflow is no longer working with helper library versions newer than 1.7.3. Edited January 4, 2020 by xilopaint
deanishe Posted June 29, 2016 Posted June 29, 2016 (edited) Sorry. That's a bug. I left a print statement in there while I was trying to debug a problem, and the unit tests didn't pick it up I've just released a new version (1.18.1) that should fix the problem. Again, very sorry about that and thanks for spotting the bug! Edited June 29, 2016 by deanishe
xilopaint Posted June 29, 2016 Author Posted June 29, 2016 Oh, no problem! Thank you for the quick fix!
xilopaint Posted June 29, 2016 Author Posted June 29, 2016 (edited) Hey deanishe, how the new auto-update feature works? Edited June 30, 2016 by xilopaint
deanishe Posted June 29, 2016 Posted June 29, 2016 http://www.deanishe.net/alfred-workflow/user-manual/update.html xilopaint and Empyreal 2
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now