Created
May 19, 2013 15:55
-
-
Save Leko/5608073 to your computer and use it in GitHub Desktop.
aojのカテゴリ検索+回答状態の確認をAlfred上で可能にします。
********************になっている部分を自分のAOJのidにして使って下さい。
表示された問題を選択すると、該当する問題が日本語で開かれます。
This file contains hidden or 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_once('workflows.php'); | |
$wf = new Workflows(); | |
/* | |
利用可能なカテゴリ一覧 | |
datamanipu データ操作 | |
string 文字列 | |
probability 確率 | |
geometry 幾何 | |
graph グラフ | |
straight ストレート | |
number 数 | |
numeric 数値の | |
simulation シミュレーション | |
combinatorial 組み合わせの | |
parsing 解析 | |
puzzle パズル | |
*/ | |
define("USER_ID", "************************"); | |
define("UNSOLVE_MESSAGE", "(unsolved)"); | |
$in = "{query}"; | |
$CATEGORIES = array( | |
"datamanipu", | |
"string", | |
"probability", | |
"geometry", | |
"graph", | |
"straight", | |
"number", | |
"numeric", | |
"simulation", | |
"combinatorial", | |
"parsing", | |
"puzzle"); | |
$REQUEST_URL = "http://judge.u-aizu.ac.jp/onlinejudge/webservice/problem_category"; | |
// パラメータにun:と付いたらun Acceptedな問題だけ抽出 | |
$unsolved_only = strpos($in, "un:") !== FALSE; | |
$param = null; | |
// オプション文字列を除去 | |
$in = str_replace("un:", "", $in); | |
// ユーザ情報の取得 | |
$user = $wf->request( "http://judge.u-aizu.ac.jp/onlinejudge/webservice/user?id=".USER_ID ); | |
$user = simplexml_load_string( utf8_encode($user) ); | |
foreach($user->solved_list->problem as $problem): | |
$solved_list[] = trim($problem->id); | |
endforeach; | |
// パラメータの処理 | |
if (preg_match("/[0-9]+/", $in)): | |
$param = "?id=".$in; | |
else: | |
if (in_array($in, $CATEGORIES)): | |
$param = "?category=".$in; | |
endif; | |
endif; | |
// 問題リストの取得 | |
if (!is_null($param)): | |
$xml = $wf->request( $REQUEST_URL.$param ); | |
$xml = simplexml_load_string( utf8_encode($xml) ); | |
// 問題が1問以上見つかれば | |
if (count($xml->problem)): | |
foreach($xml as $problem): | |
$id = trim($problem->id); | |
$score = trim($problem->score); | |
if(in_array($id, $solved_list)): | |
$solved_state = ""; | |
else: | |
$solved_state = UNSOLVE_MESSAGE; | |
endif; | |
// unsolvedオプションがOFF or unsolved | |
if(!$unsolved_only || $unsolved_only && $solved_state === UNSOLVE_MESSAGE): | |
$wf->result( time(), $id, "$id / $score $solved_state", 'Search AOJ for '.$param, 'icon.png' ); | |
endif; | |
endforeach; | |
echo $wf->toxml(); | |
// 問題/カテゴリが見つからなければ | |
else: | |
$wf->result( time(), "", "Not found problem or category...", 'Search AOJ for '.$param, 'icon.png' ); | |
echo $wf->toxml(); | |
endif; | |
// パラメータが不正 | |
else: | |
$wf->result( time(), "", "Valid parameter!", 'Search AOJ for '.$param, 'icon.png' ); | |
echo $wf->toxml(); | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment