Created
May 24, 2016 13:00
-
-
Save baramutu/497865498d5160a219e8ecfc223c9500 to your computer and use it in GitHub Desktop.
AlfredのAmazon Suggest Workflowのスクリプトフィルタを編集して、日本語が表示され、ゴミが表示されないように改変したものです
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
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
元ネタはこちら
Alfred付属のSuggest系ワークフローを一行で正常動作させる方法:
http://scrivguide.hatenadiary.jp/entry/2016/05/23/220554