Jump to content

Passing an argument into a python script


spuder

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? 

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).

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. 

Link to post
  • 3 years later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...