Created
April 6, 2013 07:59
-
-
Save scoop/5325344 to your computer and use it in GitHub Desktop.
Modified example Gist for Alfred 2 to use Amazon Suggest for Amazon.de (instead of the default Amazon.com). Note: Remove `<?php .. ?>`, which I only added for syntax highlighting purposes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require('workflows.php'); | |
$w = new Workflows(); | |
// Grab input and build query url string | |
$in = "{query}"; | |
$url = "http://completion.amazon.co.uk/search/complete?method=completion&q=".urlencode( $in )."&search-alias=aps&mkt=4&x=updateISSCompletion&noCacheIE=1295031912518"; | |
// Grab the data from Amazon | |
$str = $w->request( $url ); | |
// Strip off the "header" data | |
$str = substr( $str, strlen( 'completion = ["'.$in.'",[' ) ); | |
// Remove the node info | |
$str = substr( $str, 0, strpos( $str, ']' ) ); | |
// Check to see if results were found | |
if ( $str == "" ): | |
$w->result( time(), $in, 'No Suggestions', 'No search suggestions found. Search Amazon for '.$in, 'icon.png', 'yes' ); | |
else: | |
// Remove the double quotes around all the strings, | |
$str = str_replace( '"', '', $str ); | |
// Split into an array using a comma as the delimiter | |
$options = explode( ',', $str ); | |
// Loop through each result and make a feedback item | |
foreach( $options as $option ): | |
$w->result( time(), $option, $option, 'Find '.$option.' on Amazon', 'icon.png', 'yes', $option ); | |
endforeach; | |
endif; | |
// Return the result xml | |
echo $w->toxml(); | |
?> |
Any more document about completion search ? I'd like to know how to search Italia&UK's data.Thanks!
@scoop What does changing from mkt=1
to mkt=4
do?
I still had to change the result action in the Alfred workflow from 'Default Web Search' to 'OpenURL' using the search URL of the German store (otherwise it will open a suggestion in the .com store).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Main difference from stock PHP code:
completion.amazon.co.uk
instead ofcompletion.amazon.com
mkt=1
tomkt=4
in the query string