Everybody likes waking up, having a cup of coffee and at the same time browsing the local newspaper. Even if there’s nothing interesting there, you still want to look at the headlines. Well, in my case where I’m staying abroad, getting the latest news from my country and especially from a local newspaper, is kind of a hustle. Thank God there is RSS though! Each morning the news headlines pop into my Google Reader account and I can get a glimpse of what’s going on back home! Well that was good for me for a week. I needed more headlines and basically more erm..actual news! So I did a little bit of ‘digging’ and found out that one of the biggest local newspaper agency (Phileleftheros) back home provides a PDF version of their latest issue for free! Well it’s free for a testing period as they say! I think it’s been over a year and still they are testing it. Anyhow, the challenge was to get the newspaper every morning ready to my desktop. So I come up with the idea of an automatic newspaper fetching script. After a couple of minutes i crafter this little PHP script that calculates the URL of the next issue and then downloads it automatically.

/*	Author: Marios Tziortzis
/	Released on 12/12/2006
/	http://marios.tziortzis.com
*/
$id = 16901; // Issue on 1st of November of 2006
function days_since($d,$m,$y) {
	$nd = mktime(0,0,0,$m,$d,$y);
	return (int)((time(void)-$nd)/86400);
}
$newid = days_since(1,11,2006) + $id;
header('Location:http://pdf.phileleftheros.com/PdfEdition/Pdf.axd?i='.$newid);

Usually the newspaper agency releases the PDF file at 12:00 at noon. At that time you can set your cron job or something, to automatically retrieve the file. Just make sure your cron job says (time of execution) php -f file.php For example a daily fetch at 12:05 every day would be 05 12 * * * php -f file.phpThis can also be done through ‘wget‘ and a little bit of shell scripting. Anyway, I hope this helps.

Random Posts