Skip to content

Commit

Permalink
switching to Alfred variables for Python interp and api key
Browse files Browse the repository at this point in the history
  • Loading branch information
dfm committed May 31, 2019
1 parent 4539875 commit 4cfb8b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
32 changes: 20 additions & 12 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@
<key>escaping</key>
<integer>68</integer>
<key>script</key>
<string>if test -f "$HOME/.ads/python"; then
`cat $HOME/.ads/python` parse_query.py {query}
exit 0
fi
python parse_query.py {query}</string>
<string>$ADS_PYTHON parse_query.py {query}</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
Expand Down Expand Up @@ -151,6 +147,8 @@ python parse_query.py {query}</string>
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
<false/>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
Expand All @@ -170,11 +168,7 @@ python parse_query.py {query}</string>
<key>runningsubtext</key>
<string>Searching for papers...</string>
<key>script</key>
<string>if test -f "$HOME/.ads/python"; then
`cat $HOME/.ads/python` run_search.py {query}
exit 0
fi
python run_search.py {query}</string>
<string>$ADS_PYTHON run_search.py {query}</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
Expand All @@ -193,11 +187,11 @@ python run_search.py {query}</string>
<key>uid</key>
<string>54F6D1CC-61CC-4CD1-8853-8E956B8DB7C3</string>
<key>version</key>
<integer>2</integer>
<integer>3</integer>
</dict>
</array>
<key>readme</key>
<string></string>
<string>Search for papers using SAO/NASA Astrophysics Data System</string>
<key>uidata</key>
<dict>
<key>11D5721D-E45C-4D45-82C8-2CC370002271</key>
Expand Down Expand Up @@ -236,6 +230,20 @@ python run_search.py {query}</string>
<integer>60</integer>
</dict>
</dict>
<key>variables</key>
<dict>
<key>ADS_DEV_KEY</key>
<string></string>
<key>ADS_PYTHON</key>
<string>/Users/dforeman/anaconda3/bin/python</string>
</dict>
<key>variablesdontexport</key>
<array>
<string>ADS_PYTHON</string>
<string>ADS_DEV_KEY</string>
</array>
<key>version</key>
<string>0.1.0</string>
<key>webaddress</key>
<string>https://github.com/dfm/adsabs.alfredworkflow</string>
</dict>
Expand Down
9 changes: 7 additions & 2 deletions run_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ def set_ratelimit(ratelimit):
sub=("Or set you prefered python interpreter in the "
"~/.ads/python file"))

if not os.path.exists(os.path.expanduser("~/.ads/dev_key")):
key = os.environ.get("ADS_DEV_KEY", None)
if not len(key.strip()):
key = None
os.environ.pop("ADS_DEV_KEY")
exists = os.path.exists(os.path.expanduser("~/.ads/dev_key"))
if key is None and not exists:
return_error(("Your ADS API key must be saved in the file "
"~/.ads/dev_key"),
"~/.ads/dev_key or set as an Alfred variable"),
"https://github.com/andycasey/ads")

# Fail if we're over the rate limit
Expand Down

0 comments on commit 4cfb8b3

Please sign in to comment.