Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
api:ukazky [2017/07/19 15:19] – [stažení nahrávek hovorů] rootapi:ukazky [2019/01/23 09:55] – [stažení nahrávek hovorů] root
Line 133: Line 133:
 === PHP === === PHP ===
  
-Script below downloads all available recordings (stored at Odorik.cz) recordings from yeasterday.  To be run each night. 
  
-<code php> 
-<?php 
-$auth = array('user' => 'xxxxxx', 
-              'password' => 'yyyyyyy'); 
- 
-function calls_timespan_params() { 
-  date_default_timezone_set('Europe/Prague'); 
- 
-  $now = date_create('now'); 
-  $yesterday = date_modify($now, '-1 day'); 
- 
-  $from = date_create(date_format($yesterday, 'Y-m-d') . ' 00:00:00'); 
-  $to = date_create(date_format($yesterday, 'Y-m-d') . ' 23:59:59'); 
- 
-  return array( 'from' => date_format($from, 'c'), 
-                'to' => date_format($to, 'c')); 
-} 
- 
-function download($url) { 
-  $curl = curl_init(); 
-  curl_setopt($curl, CURLOPT_URL, $url); 
-  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
-  $data = curl_exec($curl); 
-  curl_close($curl); 
- 
-  return $data; 
-} 
- 
-function download_recording($call, $auth) { 
-  $fname = filename($call); 
- 
-  if (file_exists($fname)) { 
-    fwrite(STDERR, "file " . $fname . " (call " . $call->id . ") exists, skipping\n"); 
-    return(-1); 
-  } 
- 
-  $auth_qs = http_build_query($auth); 
-  $data = download('https://www.odorik.cz/api/v1/call_recordings/' . $fname . '?' . $auth_qs); 
- 
-  $file = fopen($fname, "w+"); 
-  fputs($file, $data); 
-  fclose($file); 
-} 
- 
-function filename($call) { 
-  #var_dump($call); 
-  #exit(0); 
- 
-  #return $call->id . '.' . $call->recording->format; 
-  return $call->date . '---' . $call->direction . '---' . $call->source_number . '---' . $call->destination_number . '.' . $call->recording->format; 
-} 
- 
-$qs = http_build_query(array_merge($auth, calls_timespan_params())); 
-$calls = json_decode(download("https://www.odorik.cz/api/v1/calls.json?" . $qs)); 
- 
-foreach($calls as $call) { 
-  if ($call->recording != NULL) { 
-    download_recording($call, $auth); 
-  } 
-} 
-?> 
-</code> 
  
  
 
api/ukazky.txt · Last modified: 2022/05/09 15:28 by root