コード例 #1
0
function search_query($kw)
{
    $wf = new Workflows();
    $url = 'http://www.bilibili.tv/search?keyword=' . urlencode($kw) . '&orderby=&formsubmit=';
    $content = $wf->request($url, array(CURLOPT_ENCODING => 1));
    $doc = phpQuery::newDocumentHTML($content);
    $list = $doc->find('li.l');
    $i = 0;
    foreach ($list as $item) {
        $link = pq($item)->children('a:first')->attr('href');
        if (strpos($link, 'http') !== 0) {
            $link = 'http://www.bilibili.tv' . $link;
        }
        $info = pq($item)->find('div.info > i');
        $author = pq($item)->find('a.upper:first')->text();
        $view = $info->eq(0)->text();
        $comment = $info->eq(1)->text();
        $bullet = $info->eq(2)->text();
        $save = $info->eq(3)->text();
        $date = $info->eq(4)->text();
        $subtitle = 'UP主:' . $author . ' 播放:' . $view . ' 评论:' . $comment . ' 弹幕:' . $bullet . ' 收藏:' . $save . ' 日期:' . $date;
        $wf->result($i, $link, pq($item)->find('div.t:first')->text(), $subtitle, 'icon.png', 'yes');
        $i++;
    }
    if (count($wf->results()) == 0) {
        $wf->result('0', $url, '在bilibili.tv中搜索', $kw, 'icon.png', 'yes');
    }
    return $wf->toxml();
}
コード例 #2
0
 /**
  * Show News.
  *
  * @return boolean|null
  */
 public function show()
 {
     $options = $this->getOptions();
     $this->log($options);
     if (empty($options)) {
         return false;
     }
     $url = $method = null;
     extract($options);
     if (!isset($url) or !isset($method)) {
         return false;
     }
     $context = stream_context_create(array('http' => array('method' => "GET", 'timeout' => 10)));
     $this->htmlDom = file_get_html($url, 0, $context);
     if ($this->htmlDom) {
         call_user_func_array(array($this, $method), array());
     }
     if (count($this->workflow->results()) == 0) {
         $this->workflow->result($method, $url, static::NEWS_NOT_FOUND_TITLE, static::NEWS_NOT_FOUND_CONTENT, static::NEWS_ICON_DEFAULT);
     }
     echo $this->workflow->toxml();
 }
コード例 #3
0
ファイル: users.php プロジェクト: ricardomatias/dotfiles
        $data = implode($output);
        $data = substr($data, strrpos($data, "X-GitHub-Request-Id"));
        // clean string
        preg_match("/([\\[{])/", $data, $matches, PREG_OFFSET_CAPTURE);
        $start = $matches[0][1];
        $end = max(strrpos($data, "}"), strrpos($data, "]")) + 1;
        $data = substr($data, $start, $end - $start);
        $repos = json_decode($data);
    } else {
        $data = $w->request($url);
        $repos = json_decode($data);
    }
    if (isset($repos->message)) {
        $w->result($repos->message, $repos->message, 'Github Limit', $repos->message, $icon, 'no');
    } else {
        foreach ($repos as $repo) {
            // repos
            if (isset($repo->full_name) && (!strlen($query) || strpos(strtolower($repo->full_name), strtolower($query)) !== false)) {
                $w->result('git-' . $repo->full_name, $repo->html_url, $repo->name, $repo->description, $icon, 'yes');
            } else {
                if (!strlen($query) || strpos(strtolower($repo->description), strtolower($query)) !== false) {
                    $w->result('git-' . $repo->id, $repo->html_url, $repo->description, $repo->html_url, $icon, 'yes');
                }
            }
        }
        if (count($w->results()) == 0) {
            $w->result('git', null, 'No Repository found', 'No Repository found that match your query', $icon, 'no');
        }
    }
}
echo $w->toxml();
コード例 #4
0
ファイル: cdn.php プロジェクト: jesseflorig/config
require_once 'workflows.php';
$w = new Workflows();
if (!isset($query)) {
    $query = "{query}";
}
$query = strtolower(trim($query));
$cdns = json_decode(file_get_contents("cdns.json"));
$output = array();
// all
if (strpos($query, " ") !== false) {
    $parts = explode(" ", $query);
    $cdn_q = array_shift($parts);
    $string = implode($parts);
    foreach ($cdns as $cdn => $params) {
        $count = count($w->results());
        $pos = strpos($cdn, $cdn_q);
        if ($pos !== false && $pos == 0) {
            run($params, $string);
            if ($count == count($w->results())) {
                $w->result("cdn-{$cdn}", $query, 'No libraries found.', $query, "icon-cache/{$cdn}.png", 'no');
            }
        }
    }
}
//
if (count($w->results()) == 0) {
    foreach ($cdns as $cdn => $params) {
        $count = count($w->results());
        run($params, $query);
        if ($count == count($w->results())) {
コード例 #5
0
ファイル: mt.php プロジェクト: Frinstio/AlfredWorkflow.com
<?php

require_once 'workflows.php';
$wf = new Workflows();
$query = trim($argv[1]);
$site = '美团';
$icon = 'icon.png';
$requestOption = array(CURLOPT_POST => true, CURLOPT_HTTPHEADER => array('Content-length:0', 'X-Requested-With:XMLHttpRequest'));
$json = $wf->request("http://www.meituan.com/search/smartbox/" . urlencode($query), $requestOption);
$items = json_decode($json);
$items = $items->data;
foreach ($items as $item) {
    $url = sprintf('http://www.meituan.com/s/?w=%s', urlencode($item));
    $subtitle = sprintf('查看全部与%s有关的团购', $item);
    $wf->result("{$url}", "在美团上搜索: {$item}", "{$subtitle}", $icon);
}
$url = sprintf('http://www.meituan.com/s/?w=', $query);
$results = $wf->results();
if (count($results) == 0) {
    $wf->result($url, 'No Suggestions', 'No search suggestions found. Search 美团 for ' . $query, 'icon.png');
}
echo $wf->toxml();
コード例 #6
0
ファイル: main.php プロジェクト: Frinstio/AlfredWorkflow.com
     $json = json_decode($json, true);
     $currentResultNumber = 1;
     foreach ($json as $item) {
         if ($currentResultNumber > $max_results) {
             break;
         }
         if (strpos(strtolower($item['data']['album']['artist']['name']), strtolower($query)) !== false || strpos(strtolower($item['data']['album']['name']), strtolower($query)) !== false || strpos(strtolower($item['data']['name']), strtolower($query)) !== false) {
             // Figure out search rank
             $popularity = $item['data']['popularity'];
             $popularity /= 100;
             // Convert popularity to stars
             $stars = floor($popularity * 5);
             $starString = str_repeat("⭑", $stars) . str_repeat("⭒", 5 - $stars);
             $subtitle = $item['data']['album']['name'] . " - <alt> play album, <cmd> play artist";
             $subtitle = "{$starString} {$subtitle}";
             if (checkIfResultAlreadyThere($w->results(), ucfirst($item['data']['album']['artist']['name']) . " - " . $item['data']['name']) == false) {
                 $w->result("spotify_mini-spotify-track" . $item['data']['uri'], $item['data']['uri'] . "|" . $item['data']['album']['uri'] . "|" . $item['data']['album']['artist']['uri'] . "|||||", ucfirst($item['data']['album']['artist']['name']) . " - " . $item['data']['name'], $subtitle, getTrackArtwork($item['data']['uri'], true), 'yes', '');
             }
             $currentResultNumber++;
         }
     }
     $w->result('', "||||activate (open location \"spotify:search:" . $query . "\")|||", "Search for " . $query . " with Spotify", "This will start a new search in Spotify", 'fileicon:/Applications/Spotify.app', 'yes', '');
     if ($is_spotifious_active == true) {
         $w->result('', "|||||" . "{$query}" . "||", "Search for " . $query . " with Spotifious", "Spotifious workflow must be installed", './images/spotifious.png', 'yes', '');
     }
 } elseif (substr_count($query, '→') == 1) {
     $words = explode('→', $query);
     $kind = $words[0];
     if ($kind == "Playlist") {
         //
         // Search playlists
コード例 #7
0
            case 'Unknown Precipitation':
                $icon = 'icons/na.png';
                break;
            case 'Unknown':
                $icon = 'icons/sun.png';
                break;
            default:
                $icon = 'icons/sun.png';
                break;
        }
        $uid = $fc->date->epoch;
        $unit = $w->get('preferred.unit', 'settings.plist');
        if ($unit == 'F') {
            $w->result($uid, 'na', $fc->date->weekday . ": " . $fc->conditions, "High: " . $fc->high->fahrenheit . "°F (" . $fc->high->celsius . "°C). Low: " . $fc->low->fahrenheit . "°F (" . $fc->low->celsius . "°C). Precipitation: " . $fc->pop . "%", $icon, 'no');
        } else {
            $w->result($uid, 'na', $fc->date->weekday . ": " . $fc->conditions, "High: " . $fc->high->celsius . "°C (" . $fc->high->fahrenheit . "°F). Low: " . $fc->low->celsius . "°C (" . $fc->low->fahrenheit . "°F). Precipitation: " . $fc->pop . "%", $icon, 'no');
        }
    }
    uasort($w->results(), 'date_sort');
}
if (!$location) {
    $w->result('weather', 'na', 'No default weather location', 'No default weather location has been set. Please set your default location with the \'weather\' command', 'icon.png', 'no');
}
echo $w->toxml();
function date_sort($a, $b)
{
    if ($a['arg'] === $b['arg']) {
        return 0;
    }
    return $a['arg'] < $b['arg'] ? -1 : 1;
}
コード例 #8
0
ファイル: main.php プロジェクト: hbcbh1999/alfred-maestro
            $macros[] = $macro;
        }
        // endforeach
    }
    // endforeach
    return $macros;
}
$macros = parse_xml();
if (!$macros) {
    $w->result('reeder.result', 'na', 'No results found', 'No search results found matching your query', 'icon.png', 'no');
} elseif ($filter) {
    // If keyword is given, do a filter
    foreach ($macros as $macro) {
        // Very simple filtering, but works quite well.
        // Real fuzzy matching would be nice, but thats a wishlist item.
        $match = strpos($macro['match'], $filter);
        if ($match !== false) {
            $w->result($macro['uid'], $macro['uid'], $macro['name'], $macro['name'], 'icon.png', 'yes');
        }
    }
    // If no matches, return this.
    if (!$w->results()) {
        $w->result('reeder.result', 'na', 'No results found', 'No macros matched your query', 'icon.png', 'no');
    }
} else {
    // Return all available macros
    foreach ($macros as $macro) {
        $w->result($macro['uid'], $macro['uid'], $macro['name'], $macro['name'], 'icon.png', 'yes');
    }
}
echo $w->toXML();