Jump to content
spuder

Passing an argument into a python script

Recommended Posts

I've completed a python script to query the puppet forge api. 

 

http://projects.puppetlabs.com/projects/module-site/wiki/Server-api

 

 

When I call the python script from the command line, it successfully returns all puppet modules desired

 

$ python myscript.py foo

 

 

When I place the same python script into an alfred workflow, and set it to require 1 argument, alfred 'gives up' the search before I've fully entered what I am looking for. 

 

 

Anyone have any ideas why Alfred doesn't wait for me to enter the entire string before searching? 

 

Here is a video showing the problem

 

 

 

*Update*

 

My code is now on github

 

https://github.com/spuder/alfred-puppet-forge

 

It turns out that if I wait long enough, the script does eventually return. The problem is that alfred is calling the script every time a new letter is entered. 

 

Searching the api gets faster each letter that is entered

 

For example: 

 

a = 1000 results

ab = 100 results

abc = 3 results

abcd = 1 result

 

So In practice, I have to wait for the results of a, ab, abc, before I can get the results of abcd. This is a 10 to 30 second delay for the data I am querying, which is far too long. 

 

How can I make alfred wait until I have finished entering abcd before executing? 

Edited by spuder

Share this post


Link to post

Anyone have any ideas why Alfred doesn’t wait for me to enter the entire string before searching? 

(…)

It turns out that if I wait long enough, the script does eventually return. The problem is that alfred is calling the script every time a new letter is entered.

That is a feature, not a bug, it was meant to work like this (not saying I like it).

 

So In practice, I have to wait for the results of a, ab, abc, before I can get the results of abcd. This is a 10 to 30 second delay for the data I am querying, which is far too long.

No, you do not. If Alfred did not yet get the response from a query and you enter something else, it’ll wait for that one, it does not “trample” itself.

 

I’ll rephrase the question. How can I make alfred wait until I have finished entering abcd before executing?

There’s not a good way to achieve this, currently, although there is a discussion somewhere on the forums on this very issue (do not recall which subforum, exactly).

Share this post


Link to post

Thanks for the information @Vitor. 

 

This 'feature' is great when a websites api is fully developed (youtube, github, ect..) It is a pain trying to use the puppet forge api because searching for 1 letter returns too many results. 

 

As a work around I've made my script exit if the argument is less than 4 characters. 

 

https://github.com/spuder/alfred-puppet-forge/blob/master/test/forge.py

 

if len(args[1]) <4:
sys.exit("module name must have at least 3 characters")

https://ask.puppetlabs.com/question/4557/limit-results-from-forge-api/

 

It looks like this might be the best I can do until alfred allows me to block partial word searches, or the puppet forge API allows limits on the number of results. I'm open to any other ideas. 

Edited by spuder

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...