Created
February 3, 2012 15:30
-
-
Save vivirenremoto/1730750 to your computer and use it in GitHub Desktop.
cron bufferapp rss updates
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 | |
// CONFIG | |
$access_token = ''; | |
$profile_ids = ''; | |
$limit = 1; | |
$urls = array( | |
'http://feeds.feedburner.com/betabeersjobs', | |
'http://feeds.feedburner.com/AgendaBetabeers', | |
'http://news.ycombinator.com', | |
'http://www.smashingmagazine.com/feed/', | |
'http://feeds.dzone.com/dzone/frontpage', | |
'http://feeds.weblogssl.com/genbetadev' | |
); | |
$fromEmail = $toEmail = "[email protected]"; | |
$subject = "Resumen " . date('d/m/Y H:i:s'); | |
// GET LATEST RSS ITEMS | |
$items = array(); | |
foreach( $urls as $url ){ | |
$xml = simplexml_load_file( $url ); | |
if( $xml->channel->item ){ | |
$aux = array(); | |
foreach( $xml->channel->item as $item ){ | |
$aux[] = $item; | |
} | |
shuffle($aux); | |
for( $i = 0; $i < $limit; $i++ ){ | |
$items[] = $aux[$i]->title . ' ' . $aux[$i]->link; | |
} | |
} | |
} | |
shuffle($items); | |
// SEND TO BUFFERAPP | |
function preparePostFields( $array ){ | |
$params = array(); | |
foreach ($array as $key => $value) { | |
$params[] = $key . '=' . urlencode($value); | |
} | |
return implode('&', $params); | |
} | |
foreach( $items as $item ){ | |
$postdata = array( | |
'text' => $item, | |
'profile_ids[]' => $profile_ids, | |
'shorten' => true, | |
'now' => false | |
); | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL,'https://api.bufferapp.com/1/updates/create.json?access_token=' . $access_token); | |
curl_setopt($curl, CURLOPT_POST, 1); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, preparePostFields( $postdata ) ); | |
curl_exec ($curl); | |
curl_close ($curl); | |
} | |
// SEND AN EMAIL RESUME | |
$header = 'From: ' . $fromEmail . " \r\n"; | |
$header .= "X-Mailer: PHP/" . phpversion() . " \r\n"; | |
$header .= "Mime-Version: 1.0 \r\n"; | |
$header .= "Content-Type: text/plain"; | |
$mensaje = utf8_decode( implode("\r\n", $items) ); | |
@mail($toEmail, $subject, $mensaje, $header); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment