day 2 at https://textb.org/t/adef_api2/
>api.edit(id='CN', title=[a,b,c])
class API {
function __construct($url) {
$this->url = $url;
}
public function _request($action, $data) {
$content = array(
'action' => $action,
'data' => json_encode($data)
);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($content),
),
);
$context = stream_context_create($options);
$result = json_decode(file_get_contents($this->url, false, $context));
return $result;
}
} l $api = new API('http://archive.arabdigitalexpression.org/api/');
//$result = $api->request('api', array("docs"=>true)); $result = $api->request('find', array( "query"=>array( "conditions"=>array(array("key"=>"*", "value"=>"paris", "operator"=>'=')) ), "keys"=>array("title", 'id'), "range"=> array(0, 10), "sort"=>array(array("key"=>"title", "operator"=>"+")) ));
var_dump($result);
easy_install ox
or
add-apt-repository ppa:j/pandora apt-get install python-ox
import ox
api = ox.API('http://archive.arabdigitalexpression.org/api/')
... other
uwe --
item = api.find({'query':{conditions:[{'key': '*', 'value':'test', 'operator':'='}], 'operator':'&'}, 'keys': ['location']})
examples: ali.py import ox import sys
name = sys.argv[1]
api = ox.API('http://archive.arabdigitalexpression.org/api/')
data = api.find({ "keys":["title","director","id","posterRatio","year"], "query":{ "conditions":[{"key":"director","value":name,"operator":"="}], "operator":"&" }, "range":[0,100], "sort":[{"operator":"+","key":"title"}] })['data']
for item in data['items']: print 'http://archive.arabdigitalexpression.org/%s/info'%item['id'], item['title'], 'by',','.join(item['director'])
and another example srt: import ox import sys
item = sys.argv[1] layer = sys.argv[2]
api = ox.API('http://archive.arabdigitalexpression.org/api/')
data = api.get(id=item, keys=['title', 'layers'])
filename = u"%s.%s.srt" % (data['data']['title'], layer) with open(filename.encode('utf-8'), 'w') as f: f.write(ox.srt.encode(data['data']['layers'][layer])) print 'created', filename
t