Skip to content

Instantly share code, notes, and snippets.

@yoshimana
Forked from baramutu/alfred_amazon_suggest_j.php
Created February 11, 2019 04:05
Show Gist options
  • Save yoshimana/748ab3c7a85ce8b0eabddbf1e96b7aea to your computer and use it in GitHub Desktop.
Save yoshimana/748ab3c7a85ce8b0eabddbf1e96b7aea to your computer and use it in GitHub Desktop.
AlfredのAmazon Suggest Workflowのスクリプトフィルタを編集して、日本語が表示され、ゴミが表示されないように改変したものです
require('workflows.php');
$w = new Workflows();
// Grab input and build query url string
$in = "{query}";
$url = "http://completion.amazon.co.jp/search/complete?method=completion&q=".urlencode( $in )."&search-alias=aps&mkt=6&x=updateISSCompletion&noCacheIE=1295031912518";
// Grab the data from Amazon
$str = $w->request( $url );
// Strip off the "header" data
$substr = mb_substr( $str, 0, mb_strpos( $str, ',' ) );
$str = mb_substr( $str, strlen( $substr ) + 2);
// Remove the node info
$str = mb_substr( $str, 0, mb_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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment