コード例 #1
0
ファイル: search.php プロジェクト: amlun/geocoding
<?php

require 'workflow.php';
require 'functions.php';
require 'GoogleMapClient.php';
isset($argv[1]) && ($query = trim($argv[1]));
$workflow = new Workflows();
$google_map_api_key = $workflow->read(GoogleMapClient::APIKEY);
$client = new GoogleMapClient($google_map_api_key);
try {
    if (is_geo($query)) {
        $params['latlng'] = $query;
    } else {
        $params['address'] = $query;
    }
    $result = $client->geocode($params);
    if ($result['status'] != 'OK') {
        $workflow->result('alfredworkflow_404', $result['status'], $result['status'], 'No response, try again!', 'icon/google.png');
    } else {
        foreach ($result['results'] as $address) {
            $address_location = $address['geometry']['location'];
            $latlng = $address_location['lat'] . ',' . $address_location['lng'];
            $workflow->result($address['place_id'], $latlng, $address['formatted_address'], $query, 'icon/google.png');
        }
    }
} catch (Exception $e) {
    $workflow->result('alfredworkflow_500', 'Please make sure your internet works well.', 'No response, try again!', 'Please make sure your internet works well.', 'icon/google.png');
}
print $workflow->toxml();
コード例 #2
0
ファイル: query.php プロジェクト: amlun/geocoding
<?php

require 'workflow.php';
require 'functions.php';
require 'BaiduMapClient.php';
isset($argv[1]) && ($query = trim($argv[1]));
$workflow = new Workflows();
$baidu_map_api_key = $workflow->read(BaiduMapClient::APIKEY);
$place_client = BaiduMapClient::instance('geocoder', $baidu_map_api_key);
// 'EBfee57431c42ec5925b2e9e32c5313b'
try {
    if (is_geo($query)) {
        $params['location'] = $query;
    } else {
        $params['address'] = $query;
    }
    $result = $place_client->default($params);
    if (!$result || $result['status'] != 0) {
        $workflow->result($result['status'], '找不到地址!', $result['message'], '找不到相应的地址,请重试!', 'icon/baidu.png');
    } else {
        $result = $result['result'];
        if (isset($result['business']) && $result['formatted_address'] && isset($result['addressComponent'])) {
            $workflow->result($query, $result['business'], $result['formatted_address'], $query, 'icon/baidu.png');
            foreach ($result['addressComponent'] as $key => $value) {
                if (empty($value)) {
                    continue;
                }
                $workflow->result($key . ':' . $value, $value, $value, $key, 'icon/baidu.png');
            }
        } elseif (isset($result['location'])) {
            $latlng = $result['location']['lat'] . ',' . $result['location']['lng'];
コード例 #3
0
            echo $q;
        }
        return;
        break;
}
if ($rgba == false) {
    $w->result('tylereich.colors-noresults', '', 'No matching colors were found', 'Make sure you spelled your query correctly.', 'icon.png', 'no');
    echo $w->toxml();
    return;
}
$r = $rgba[0];
$g = $rgba[1];
$b = $rgba[2];
$a = $rgba[3];
$hexraw = tohexraw($r, $g, $b, $a);
if (!$w->read($w->cache() . "/{$hexraw}.png")) {
    $img_rgba = array(round($r * 255), round($g * 255), round($b * 255), round(abs($a - 1) * 127));
    $img = imagecreatefrompng('checker.png');
    $color = imagecolorallocatealpha($img, $img_rgba[0], $img_rgba[1], $img_rgba[2], $img_rgba[3]);
    imagefilledrectangle($img, 8, 8, 120, 120, $color);
    imagepng($img, $w->cache() . "/{$hexraw}.png");
    imagedestroy($img);
}
if ($a == 1) {
    $a = false;
}
$hex = tohex($r, $g, $b, $a);
//$hexraw = tohexraw($r,$g,$b,$a);
$hsl = tohsl($r, $g, $b, $a);
$name = toname(tohexraw($r, $g, $b));
$rgb = torgb($r, $g, $b, $a);
コード例 #4
0
            $hex .= substr('0' . dechex($c / 65535 * 255), -2);
        }
    }
    return `osascript -e 'tell application "Alfred 2" to search "hue {$id}:color:{$hex}"'`;
}
/** Cache a reference to lights. */
if (trim($query) === '') {
    // clear cache
    $lights = $w->write('', 'lights');
    $lights = $w->request("http://{$bridge_ip}" . $base_path . '/lights', array(CURLOPT_CONNECTTIMEOUT => 3));
    $lights = json_decode($lights, true);
    if ($lights) {
        $w->write($lights, 'lights');
    }
} else {
    $lights = $w->read('lights', true);
}
if (!$lights) {
    result(array('title' => 'Bridge connection failed.', 'subtitle' => 'Try running "setup-hue".', 'valid' => 'no'));
    echo $w->toxml($results);
    exit;
}
/** Generate Results */
if ($query == 'lights') {
    foreach ($lights as $id => $light) {
        result(array('uid' => "light_{$id}", 'title' => $light['name'], 'valid' => 'no', 'autocomplete' => "{$id}:"));
    }
} elseif (isset($lights[$query])) {
    $id = $query;
    $light = $lights[$id];
    result(array('uid' => "light_{$id}", 'title' => $light['name'], 'valid' => 'no', 'autocomplete' => "{$id}:"));
コード例 #5
0
ファイル: main.php プロジェクト: bycEEE/env
require './src/functions.php';
require './src/menu.php';
require_once './src/workflows.php';
// $begin_time = computeTime();
// Report all PHP errors
//error_reporting(E_ALL);
error_reporting(0);
$w = new Workflows('com.vdesabou.spotify.mini.player');
$query = escapeQuery($argv[1]);
// thanks to http://www.alfredforum.com/topic/1788-prevent-flash-of-no-result
$query = iconv('UTF-8-MAC', 'UTF-8', $query);
//
// check for library update in progress
$update_in_progress = false;
if (file_exists($w->data() . '/update_library_in_progress')) {
    $in_progress_data = $w->read('update_library_in_progress');
    $update_library_in_progress_words = explode('▹', $in_progress_data);
    $elapsed_time = time() - $update_library_in_progress_words[3];
    $update_in_progress = true;
    if (!file_exists($w->data() . '/library_old.db')) {
        if (startsWith($update_library_in_progress_words[0], 'Init')) {
            if ($elapsed_time < 1800) {
                $w->result(null, $w->data() . '/update_library_in_progress', 'Initialization phase since ' . beautifyTime($elapsed_time, true) . ' : ' . floatToSquares(0), 'Waiting for Spotify servers to return required data, it may take time depending on your library', './images/update_in_progress.png', 'no', null, '');
            } else {
                $w->result(null, '', 'There is a problem, the initialization phase took more than 30 minutes', 'Choose kill update library below, and report to the author', './images/warning.png', 'no', null, '');
                $w->result(null, serialize(array('', '', '', '', '', '', '', 'kill_update', $alfred_playlist_uri, '', '', '', '', '', '', '', '', $alfred_playlist_name, $now_playing_notifications, $is_alfred_playlist_active, $country_code, $userid)), 'Kill update library', 'This will stop the library update', './images/kill.png', 'yes', '');
            }
        } else {
            if ($update_library_in_progress_words[0] == 'Refresh Library') {
                $type = 'playlists';
            } elseif ($update_library_in_progress_words[0] == 'Artists') {