#!/usr/bin/perl #-----------------------------------------------------------------------------# # LRHeadlines (Linux Review headline grabber) # # Copyright (C) 2000 M.A.H. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # (http://hammer.prohosting.com/~runlinux/) (email : linuxwebmaster@yahoo.com) # # # Updated: 2/01/2000 # Version 1.0 # # Adapted from: # The Freshmeat headline grabber script. # # Written by Srijith.K # (http://www.srijith.net) (email : webmaster@srijith.net) # # Version 2.01 # #----------------------------------------------------------------------------# #------------------------------------------------------------------------------# # Usage : (1) Change the first line of script to point to the perl interpreter. # (2) Change the value of variables, if required. # (3) Lather. Rinse. Repeat. #------------------------------------------------------------------------------# #---- Modules used(to 'get' the backend file & for file manipulation)-------# use LWP::Simple; use CGI; #---------------------------------------------------------------------------# #---- Varibles ----# $updatefile="update.txt"; # time of last update $localfile = "linuxreview.out"; # where the headlines are stored $update_interval=60; # interval in minutes at which the file is fetched fresh from server #------------------# ############ ~~~ EDITING THE FOLLOWING WITHOUT KNOWLEDGE OF PERL IS INJURIOUS TO SCRIPT HEALTH ~~~~ ########### print "pragma:no-cache\n"; print "content-type:text/html\n\n"; #---- Fetching the File ---------# # First check if the file in server is old. If yes, fetch new file $current_time=time; # The current time open(UPDATE, $updatefile) || die "Error opening update log file!\n"; $update_file_content = new CGI(UPDATE); close(UPDATE); $freshmeat = $update_file_content->param('freshmeat'); $update_interval_sec=$update_interval*60; $new_update_time=$freshmeat + $update_interval_sec; if($current_time>$new_update_time) { # Ok.. File is too old.. Fetch new file from server. # The $url points to the text file that stores the headlines. $url = 'http://hammer.prohosting.com/~runlinux/announcements.txt' ; $document = get($url) or do { # Trouble fetching file from server.. !! print "Can't get backend file from the server." ; exit (0) ; } ; @document = split /\n/, $document; # Save into local file open(LOCALFILE,">$localfile") || die "Cannot open the local file for write\n"; flock(LOCALFILE,2); foreach $line (@document) { print LOCALFILE "$line\n"; } flock(LOCALFILE,8); close(LOCALFILE); # Update the update_time and save into file $update_file_content->param('freshmeat',$current_time); open(UPDATE,">$updatefile") || die "Error opening counter file!\n"; flock(UPDATE, 2); # locks the file - 2 to lock, 8 to unlock $update_file_content->save(UPDATE); flock(UPDATE, 8); # unlock file close(UPDATE); } # ################################################################## # ## Now open the locally stored linuxreview file # # $document=""; open (LOCALFILE,"<$localfile"); while() { $document=$document.$_; } close(LOCALFILE); @document = split /\n/, $document; $document =~ s/%%/ / ; @document = split /%%/, $document ; print "Linux Review Headlines

\n\n"; for ($counter1 =0; $counter1<$#document+1;$counter1=$counter1+1) { print "\n"; ( @news_array ) = split /\n/, $document[$counter1] ; $counter2=$counter1+1; print "\n$news_array[1]
\n"; } print ""; #---- The End ------#