Skip to content

Commit

Permalink
Make engines compatible with Go
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Dec 11, 2017
1 parent 85896bf commit 0881eb1
Show file tree
Hide file tree
Showing 34 changed files with 855 additions and 1,536 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
/.autoenv.zsh
/.autoenv_leave.zsh

# Build binary
/src/search

# Ignore private info files
/src/info.dist.plist
/src/info.bak.plist
Expand Down
195 changes: 62 additions & 133 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,167 +1,98 @@
# Searchio! workflow for Alfred #
Searchio! workflow for Alfred
=============================

Auto-suggest search results from multiple search engines and languages.

![Searchio! Demo][demo]


Contents
--------

<!-- MarkdownTOC autolink="true" bracket="round" depth="3" autoanchor="true" -->

- [Download and installation](#download-and-installation)
- [Usage](#usage)
- [Configuration](#configuration)
- [Importing Searches](#importing-searches)
- [Adding Engines](#adding-engines)
- [Licensing, thanks](#licensing-thanks)

<!-- /MarkdownTOC -->

Supports the following search engines/websites:

- Amazon
- Bing
- DuckDuckGo
- eBay
- Google
- Google Images
- Google Maps
- YouTube
- Google Maps (requires a Google Places API key)
- Naver
- Wikia (only the top ~200 wikis, but you can [import](#importing-searches) any others)
- Wikipedia
- Wiktionary
- Amazon
- eBay
- DuckDuckGo
- Bing
- Yahoo!
- Ask.com
- Yandex.ru
- Naver.com
- Wikia.com

## Download and installation ##

Download the latest version from the [GitHub releases page](https://github.com/deanishe/alfred-searchio/releases/latest) or [Packal](http://www.packal.org/workflow/searchio).

## Usage ##

There are several searches pre-configured. Only some have keywords (i.e. can be used as-is):

- `g` — Search Google in system (i.e. default) language
- `m` — Search Google Maps in system (i.e. default) language
- `gi` — Search Google Images in system (i.e. default) language
- `w` — Search Wikipedia in system (i.e. default) language
- `wn` — Search Wiktionary in system (i.e. default) language
- `a` — Search Amazon in system (i.e. default) language. If your system language is English, this will search Amazon.com. Use `-l uk` in the Script Filter to search Amazon.co.uk or `-l ca` to search Amazon.ca.
- `yt` — Search YouTube in system (i.e. default) language
- `searchio [<query>]` — Show settings and list of supported search engines. Currently, the only setting is a toggle to also show the `<query>` in the results list (default: `No`).
- `searchiohelp` — Open help (this README) in your browser

Most of the other available search engines also have an example Script Filter configured, but without a keyword. Add a keyword if you wish to use one of the examples.

Several of the Script Filters demonstrate the use of the `--lang` (or `-l`) option to the `search.py` script to search in a different language/region. See [the Languages section](#languages) for more information.

To add a new search, either copy/paste an existing Script Filter, or create a new one as follows:

![][screen1]

**Note:** Be sure to select the same escaping options as in the screenshot (Backquotes, Double Quotes, Backslashes, Dollars).

By default, your system language will be used. To specify a custom language:

![][screen2]

**Note:** Be sure to connect the Script Filter to the Open URL action or it won't work.

## Icons ##

Icons for each search engine can be found in the `icons` subirectory of the Workflow.

## Languages ##

The `-l` or `--lang` argument to `search.py` doesn't follow any hard-and-fast rules: it depends on the search engine you're using. With some search engines (Google, Wikipedia, Wiktionary, Bing, DuckDuckGo), it's a language, e.g. `uk` = Ukrainian. In others (Yahoo!, Amazon, Ask), it's treated as a region, e.g. `uk` = United Kingdom.

Some search engines (Bing, DuckDuckGo, eBay) do not provide language-specific suggestions, but actioning the result will open a list of language-specific results in your browser.

## Search engines ##

The following search engines are supported. Pass the `ID` to the `-e`/`--engine` argument of `search.py` to search using that engine. If `--engine` is not specified, Google will be used.

| ID | Name |
|---------------|---------------|
| amazon | Amazon |
| ask | Ask |
| bing | Bing |
| ddg | DuckDuckGo |
| ebay | eBay |
| google | Google |
| google-images | Google Images |
| google-maps | Google Maps |
| naver | Naver.com |
| wikia | Wikia |
| wikipedia | Wikipedia |
| wiktionary | Wiktionary |
| yahoo | Yahoo! |
| yandex | Yandex.ru |
| youtube | YouTube |

### Wikipedia, Wiktionary ###

The `--lang` argument will be treated as a subdomain, e.g. `de` will retrieve results from `de.wikipedia.org`.

### Google ###

The `--lang` argument should work for [any language supported by Google](https://www.google.com/preferences#languages), with the obvious exceptions of things like Klingon and Hacker…

### Bing, DuckDuckGo, eBay ###

Bing, eBay and DuckDuckGo do not provide language-specific suggestions, but the results opened in your browser should be restricted to the specified language/region.

### Ask, Amazon, Yahoo! ###

Ask.com, Amazon and Yahoo! do not provide language-specific search suggestions/results, but rather region-specific ones. In many cases, this won't make a difference (e.g. `--lang de` and `--lang fr` will provide German and French results respectively), however the behaviour is different in some cases, e.g. `uk` means "United Kingdom", not "Ukrainian".
- Yandex
- YouTube
- **plus** it can [import a search configuration](#importing-searches) from *any* website that supports OpenSearch autosuggestions

### Wikia.com ###

Wikia.com is a special case. Instead of languages or regions, the `--lang` option is used to set a specific wiki, e.g. `--lang gameofthrones` will search `gameofthrones.wikia.com`.
<a name="download-and-installation"></a>
Download and installation
-------------------------

You *must* specify a `--lang` option for Wikia searches.
Download the latest version from the [GitHub releases page](https://github.com/deanishe/alfred-searchio/releases/latest).

## Examples ##

Use these in the `Script` field of a Script Filter.
<a name="usage"></a>
Usage
-----

```bash
# Google (default engine) in your system (default) language
/usr/bin/python search.py "{query}"
There are several example searches pre-configured:

# Google in German
/usr/bin/python search.py -l de "{query}"
- `g` — Search Google in English
- `gd` — Search Google in German
- `w` — Search the English Wikipedia
- `wd` — Search the German Wikipedia
- `yt` — Search the United States version of YouTube
- `ytd` — Search the German version of YouTube

# Google in French
/usr/bin/python search.py -l fr "{query}"

# YouTube in Brazilian Portuguese
/usr/bin/python search.py -e youtube -l pt-BR "{query}"
<a name="configuration"></a>
### Configuration ###

# Amazon.co.uk
/usr/bin/python search.py -e amazon -l uk "{query}"
There is a single variable in the workflow configuration screen (open the workflow in Alfred Preferences and hit the `[𝒙]` button): `GOOGLE_PLACES_API_KEY`. You must set this to use Google Maps search. You can get an API key [here](https://developers.google.com/places/web-service/get-api-key).

# Amazon.ca
/usr/bin/python search.py -e amazon -l ca "{query}"
- `searchio [<query>]` — Show workflow settings
- `Update Available …` — Shown if there is a new version of the workflow available to download. Action the item to install it.
- `Installed Searches …` — View and delete your configured searches
- `All Engines …` — View supported engines and add new searches
- `Import Search …` — Import a new search configuration from a URL (see [Importing Searches](#importing-searches))
- `Reload` — Regenerate the workflow's Script Filters from your configured searches (and clean the cache). Run this if you screw up the Script Filters or an update overwrites them.
- `Online Help` — Open this page in your browser.
- `Workflow up to Date` — You have the latest version of the workflow. Action this item to force a check for a new version.

# DuckDuckGo in system (default) language
/usr/bin/python search.py -e ddg "{query}"

# DuckDuckGo in Spanish
/usr/bin/python search.py -e ddg -l es "{query}"
<a name="importing-searches"></a>
### Importing Searches ###

# Yahoo! UK
/usr/bin/python search.py -e yahoo -l uk "{query}"
Searchio! has the ability to import a search configuration from any website that supports the OpenSearch autosuggestion API.

# Yahoo! Australia
/usr/bin/python search.py -e yahoo -l au "{query}"
Run `searchio` > `Import Search …` and the workflow will offer to import a search from a URL on your clipboard, the frontmost Safari tab or the frontmost Chrome tab.

# Wikipedia in Simple English
/usr/bin/python search.py -e wikipedia -l simple "{query}"
It will try to find and read the OpenSearch description at the URL and import it (and the website's icon if available), then ask you to assign a keyword for the search.

# Wikipedia in Polish
/usr/bin/python search.py -e wikipedia -l pl "{query}"
**NOTE**: Although many websites support OpenSearch, few support the autosuggestion API that Searchio! uses. Sites based on MediaWiki usually support the API, so you can add all your favourite Wikia wikis (the built-in Wikia engine only supports the few hundred most popular wikis).

# Wiktionary in Spanish
/usr/bin/python search.py -e wiktionary -l es "{query}"

# Game of Thrones wiki at Wikia.com
/usr/bin/python search.py -e wikia -l gameofthrones "{query}"
<a name="adding-engines"></a>
Adding Engines
--------------

# Borderlands wiki at Wikia.com
/usr/bin/python search.py -e wikia -l borderlands "{query}"
```
TODO

<a name="licensing-thanks"></a>
## Licensing, thanks ##

The code in this workflow is released under the [MIT Licence](http://opensource.org/licenses/MIT).
Expand All @@ -172,5 +103,3 @@ This workflow uses the [Alfred-Workflow](http://www.deanishe.net/alfred-workflow


[demo]: ./docs/demo.gif
[screen1]: http://www.deanishe.net/alfred-searchio/screen1.png
[screen2]: http://www.deanishe.net/alfred-searchio/screen2.png
Binary file removed Searchio!-2.0.0-alpha1.alfredworkflow
Binary file not shown.
Binary file added Searchio!-2.0.0-rc1.alfredworkflow
Binary file not shown.
2 changes: 1 addition & 1 deletion bin/gen_ddg.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def variants():
def main():
"""Print DDG engine JSON to STDOUT."""
data = mkdata(u'Duck Duck Go', u'Alternative search engine',
jsonpath='[*].phrase',)
jsonpath='$[*].phrase',)

for v in variants():
s = mkvariant(v.id.lower(), v.name,
Expand Down
7 changes: 4 additions & 3 deletions bin/gen_google_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
from google import google_search

SEARCH_URL = 'https://www.google.com/maps/search/{{query}}?hl={hl}'
SUGGEST_URL = 'https://maps.googleapis.com/maps/api/place/queryautocomplete/json?input={{query}}&language={hl}&key={{GOOGLE_PLACES_API_KEY}}'

SUGGEST_URL = 'https://maps.googleapis.com/maps/api/place/queryautocomplete/json?input={{query}}&language={hl}&key=${{GOOGLE_PLACES_API_KEY}}'
JSON_PATH = '$.predictions[*].description'

if __name__ == '__main__':
google_search(SEARCH_URL, SUGGEST_URL, u'Google Maps', u'Location search')
google_search(SEARCH_URL, SUGGEST_URL, u'Google Maps', u'Location search',
jsonpath=JSON_PATH)
10 changes: 8 additions & 2 deletions bin/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,23 @@ def langs():
yield Lang(*[s.decode('utf-8') for s in line])


def google_search(search_url, suggest_url, title, description):
def google_search(search_url, suggest_url, title, description, jsonpath=None):
"""Generate an engine definition for a Google search.
Args:
search_url (str): Search URL template
suggest_url (str): Suggest URL template
title (unicode): Engine title
description (unicode): Engine description
jsonpath (unicode, optional): JSONPath for results
"""
data = mkdata(title, description)
kwargs = {}
if jsonpath:
kwargs['jsonpath'] = jsonpath

data = mkdata(title, description, **kwargs)

for l in langs():
s = mkvariant(l.id.lower(), l.name,
u'{} ({})'.format(title, l.name),
Expand Down
Loading

0 comments on commit 0881eb1

Please sign in to comment.