simple php xml reader & posting to koornk

5 views
Skip to first unread message

matija

unread,
Jan 12, 2009, 12:15:59 PM1/12/09
to koornk API
here's simple xml reader for tv listing (rtvslo.si - tv slo1) and
posting cartoons as status to koornk.com

about: http://www.rtvslo.si/xmlspored
feed url (2009-01-12):
http://www.rtvslo.si/modload.php?&c_mod=rspored-v2&izbran_dan=2009-01-12&izbran_program=1&s_content=xml
result: @risanka - http://koornk.com/user/risanka/

<?php
// link to xml
$link = 'http://www.rtvslo.si/modload.php?&c_mod=rspored-
v2&izbran_dan=' . date('Y-m-d') . '&izbran_program=1&s_content=xml';
// fetch
$xml_data = simplexml_load_file($link);
$cartoons = array();
if (isset($xml_data->spored)) {
// loop trough data
foreach ($xml_data->spored as $spored) {
$title = (string) $spored->naslov;
$time = (int) str_replace(":", "", (string) $spored->ura);
if ( mb_strpos( $title, ", RISANKA") !== false && $time > 1800 &&
$time < 1900 ) {
// fill array with fetched data
$cartoons[] = array(
'title' => trim( ucwords( mb_strtolower( str_replace(",
RISANKA", "", $title) )) ),
'time' => (string) $spored->ura
);
}
}
}
if (!empty($cartoons)) {
// generate string for posting
foreach ($cartoons as $key => $value) {
if (isset($output)) { $output .= ", "; } else { $output = ""; }
$output .= $value['time'] . " " . $value['title'];
}

// curl init & post
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "http://www.koornk.com/api/
update");
// set valid username and password
curl_setopt($curl_handle, CURLOPT_USERPWD, "--username--:--
password--");
curl_setopt($curl_handle, CURLOPT_POST, true);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, array("status" =>
$output));
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
$return_data = curl_exec($curl_handle);
$return_status = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE);
curl_close($curl_handle);
}
?>

i also created cronjob to run every day at 17.00:
00 17 * * * /usr/bin/php -f koornk-risanka.php
Reply all
Reply to author
Forward
0 new messages