Gossamer Forum
Home : Products : Links 2.0 : Customization :

Help with RSS

Quote Reply
Help with RSS
Hello,

i have written a small script which extracts the new entrys from the db as an rss file.

I call it via cron this way:

/srv/www/htdocs/web8/html/cgi-bin/./rssoutput.pl>/srv/www/htdocs/web8/html/rss/rss.xml

Can someone help me by modifying it, so that i can call it via the browser on demand?


#!/usr/bin/perl -w
$rssdate = &get_rssdate;
$time = &get_time;
open (DATEI, "/srv/www/htdocs/web8/html/cgi-bin/links/admin/data/links.db");
flock (DATEI, 2);
@storeit = <DATEI>;
close DATEI;
# print "Content-type: text/plain\n\n";
print <<EOT;
<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
<title>domain.de RSS Feed</title>
<link>http://www.domain.de</link>
<description>domain.de RSS Feed</description>
<language>de</language>
<lastBuildDate>$rssdate $time +0000</lastBuildDate>
<copyright>News</copyright>
EOT
foreach $entrys (@storeit){
chomp($entrys);
($id,$titel,$url,$datum,$kategorie,$description,$name,$email,$hits,$isNew)=split(/\|/,$entrys);
if ($isNew eq "Yes") {
$sponsor = "";
if ($entrys =~ m/Sponsor/) {
$sponsor = "(Werbung)";
}
$titel =~ s/&/&#38;/g;
$titel =~ s/</&#60;/g;
$titel =~ s/>/&#62;/g;
$titel =~ s/’/'/g;
$titel =~ s/€/Euro/g;
$titel =~ s/£/&#163;/g;
$titel =~ s/©/&#169;/g;
$titel =~ s/®/&#174;/g;
$titel =~ s/«/&#171;/g;
$titel =~ s/»/&#187;/g;
$titel =~ s/"/&quot;/g;
$titel =~ s/–/-/g;
$description =~ s/&/&#38;/g;
$description =~ s/</&#60;/g;
$description =~ s/>/&#62;/g;
$description =~ s/’/'/g;
$description =~ s/€/Euro/g;
$description =~ s/£/&#163;/g;
$description =~ s/©/&#169;/g;
$description =~ s/®/&#174;/g;
$description =~ s/«/&#171;/g;
$description =~ s/»/&#187;/g;
$description =~ s/"/&quot;/g;
$description =~ s/–/-/g;
$description =~ s/\015\012|\015|\012/ /sg;
$description =~ s/ / /g;
$description =~ s/`+/ /g;
print <<EOT;
<item>
<title>$titel</title>
<description>$description $sponsor - Eintrag vom $datum</description>
<link>http://www.domain.de/Detailed/$id.shtml</link>
<guid>http://www.domain.de/Detailed/$id.shtml</guid>
</item>
EOT
}
}
print <<EOT;
</channel>
</rss>
EOT
sub get_rssdate {
# --------------------------------------------------------
# Returns the current date.
#
my ($time1) = $_[0];
($time1) or ($time1 = time());
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time1-3600);
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
my @days = qw!Sun Mon Tue Wed Thu Fri Sat!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;
return "$days[$dweek], $day $months[$mon] $year";
}
sub get_time {
# --------------------------------------------------------
# Returns the time in the format "hh-mm-ss".
#
my $time = shift;
$time ||= time();
my ($sec, $min, $hour, @junk) = localtime ($time-3600);
($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");

return "$hour:$min:$sec";
}

Best, Karl
Quote Reply
Re: [Karl] Help with RSS In reply to
Hi,

Can you pleas paste it back, with the [code] [/code] tags, so we can read it easier? Hard to see whats going on where :P

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Help with RSS In reply to
oops, sorry


Code:


#!/usr/bin/perl -w
$rssdate = &get_rssdate;
$time = &get_time;
open (DATEI, "/srv/www/htdocs/web8/html/cgi-bin/links/admin/data/links.db");
flock (DATEI, 2);
@storeit = <DATEI>;
close DATEI;
# print "Content-type: text/plain\n\n";
print <<EOT;
<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
<title>domain.de RSS Feed</title>
<link>http://www.domain.de</link>
<description>domain.de RSS Feed</description>
<language>de</language>
<lastBuildDate>$rssdate $time +0000</lastBuildDate>
<copyright>News</copyright>
EOT
foreach $entrys (@storeit){
chomp($entrys);
($id,$titel,$url,$datum,$kategorie,$description,$name,$email,$hits,$isNew)=split(/\|/,$entrys);
if ($isNew eq "Yes") {
$sponsor = "";
if ($entrys =~ m/Sponsor/) {
$sponsor = "(Werbung)";
}
$titel =~ s/&/&#38;/g;
$titel =~ s/</&#60;/g;
$titel =~ s/>/&#62;/g;
$titel =~ s/’/'/g;
$titel =~ s/€/Euro/g;
$titel =~ s/£/&#163;/g;
$titel =~ s/©/&#169;/g;
$titel =~ s/®/&#174;/g;
$titel =~ s/«/&#171;/g;
$titel =~ s/»/&#187;/g;
$titel =~ s/"/&quot;/g;
$titel =~ s/–/-/g;
$description =~ s/&/&#38;/g;
$description =~ s/</&#60;/g;
$description =~ s/>/&#62;/g;
$description =~ s/’/'/g;
$description =~ s/€/Euro/g;
$description =~ s/£/&#163;/g;
$description =~ s/©/&#169;/g;
$description =~ s/®/&#174;/g;
$description =~ s/«/&#171;/g;
$description =~ s/»/&#187;/g;
$description =~ s/"/&quot;/g;
$description =~ s/–/-/g;
$description =~ s/\015\012|\015|\012/ /sg;
$description =~ s/ / /g;
$description =~ s/`+/ /g;
print <<EOT;
<item>
<title>$titel</title>
<description>$description $sponsor - Eintrag vom $datum</description>
<link>http://www.domain.de/Detailed/$id.shtml</link>
<guid>http://www.domain.de/Detailed/$id.shtml</guid>
</item>
EOT
}
}
print <<EOT;
</channel>
</rss>
EOT
sub get_rssdate {
# --------------------------------------------------------
# Returns the current date.
#
my ($time1) = $_[0];
($time1) or ($time1 = time());
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time1-3600);
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
my @days = qw!Sun Mon Tue Wed Thu Fri Sat!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;
return "$days[$dweek], $day $months[$mon] $year";
}
sub get_time {
# --------------------------------------------------------
# Returns the time in the format "hh-mm-ss".
#
my $time = shift;
$time ||= time();
my ($sec, $min, $hour, @junk) = localtime ($time-3600);
($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");

return "$hour:$min:$sec";
}


Best,
Karl
Quote Reply
Re: [Karl] Help with RSS In reply to
Hi,

Should be as simple as using this:

Code:
#!/usr/bin/perl -w
$rssdate = &get_rssdate;
$time = &get_time;
open (DATEI, "/srv/www/htdocs/web8/html/cgi-bin/links/admin/data/links.db");
flock (DATEI, 2);
@storeit = <DATEI>;
close DATEI;
print "Content-type: application/xml\n\n";
print <<EOT;
<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
<title>domain.de RSS Feed</title>
<link>http://www.domain.de</link>
<description>domain.de RSS Feed</description>
<language>de</language>
<lastBuildDate>$rssdate $time +0000</lastBuildDate>
<copyright>News</copyright>
EOT
foreach $entrys (@storeit){
chomp($entrys);
($id,$titel,$url,$datum,$kategorie,$description,$name,$email,$hits,$isNew)=split(/\|/,$entrys);
if ($isNew eq "Yes") {
$sponsor = "";
if ($entrys =~ m/Sponsor/) {
$sponsor = "(Werbung)";
}
$titel =~ s/&/&#38;/g;
$titel =~ s/</&#60;/g;
$titel =~ s/>/&#62;/g;
$titel =~ s/’/'/g;
$titel =~ s/€/Euro/g;
$titel =~ s/£/&#163;/g;
$titel =~ s/©/&#169;/g;
$titel =~ s/®/&#174;/g;
$titel =~ s/«/&#171;/g;
$titel =~ s/»/&#187;/g;
$titel =~ s/"/&quot;/g;
$titel =~ s/–/-/g;
$description =~ s/&/&#38;/g;
$description =~ s/</&#60;/g;
$description =~ s/>/&#62;/g;
$description =~ s/’/'/g;
$description =~ s/€/Euro/g;
$description =~ s/£/&#163;/g;
$description =~ s/©/&#169;/g;
$description =~ s/®/&#174;/g;
$description =~ s/«/&#171;/g;
$description =~ s/»/&#187;/g;
$description =~ s/"/&quot;/g;
$description =~ s/–/-/g;
$description =~ s/\015\012|\015|\012/ /sg;
$description =~ s/ / /g;
$description =~ s/`+/ /g;
print <<EOT;
<item>
<title>$titel</title>
<description>$description $sponsor - Eintrag vom $datum</description>
<link>http://www.domain.de/Detailed/$id.shtml</link>
<guid>http://www.domain.de/Detailed/$id.shtml</guid>
</item>
EOT
}
}
print <<EOT;
</channel>
</rss>
EOT
sub get_rssdate {
# --------------------------------------------------------
# Returns the current date.
#
my ($time1) = $_[0];
($time1) or ($time1 = time());
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time1-3600);
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
my @days = qw!Sun Mon Tue Wed Thu Fri Sat!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;
return "$days[$dweek], $day $months[$mon] $year";
}
sub get_time {
# --------------------------------------------------------
# Returns the time in the format "hh-mm-ss".
#
my $time = shift;
$time ||= time();
my ($sec, $min, $hour, @junk) = localtime ($time-3600);
($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");

return "$hour:$min:$sec";
}

(add the line in red)

Then, make sure its CHMOD'ed to 755 (for testing, I would recommend just renaming it as test.cgi)

Personally, I wouldn't really recommend doing this dynamically though, as it could very well corrupt your .db file, if used by too many people (even with flock)

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Help with RSS In reply to
Hello Andy,

thank you very much for your answer. You missunderstand me.

In the moment i call the script as it is via cron every 2 hours via the command line in the first posting.

What i need is a version where i call the script via the browser on demand (from the protected admin area) and then the script writes the rss file into directory /srv/www/htdocs/web8/html/rss/rss.xml

So i need an write routine. My knowledge in perl is only good for little modifications.

Best,
Karl
Quote Reply
Re: [Karl] Help with RSS In reply to
Hi,

Ah, sorry - try this.

Code:
#!/usr/bin/perl -w

use CGI::Carp qw(fatalsToBrowser);

$rssdate = &get_rssdate;
$time = &get_time;
open (DATEI, "/srv/www/htdocs/web8/html/cgi-bin/links/admin/data/links.db");
flock (DATEI, 2);
@storeit = <DATEI>;
close DATEI;
print "Content-type: text/html \n\n";

open (WRITEIT, ">/srv/www/htdocs/web8/html/rss/rss.xml") || die qq|Can't write /srv/www/htdocs/web8/html/rss/rss.xml . Reason: $!|;

print WRITEIT <<EOT;
<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
<title>domain.de RSS Feed</title>
<link>http://www.domain.de</link>
<description>domain.de RSS Feed</description>
<language>de</language>
<lastBuildDate>$rssdate $time +0000</lastBuildDate>
<copyright>News</copyright>
EOT
foreach $entrys (@storeit){
chomp($entrys);
($id,$titel,$url,$datum,$kategorie,$description,$name,$email,$hits,$isNew)=split(/\|/,$entrys);
if ($isNew eq "Yes") {
$sponsor = "";
if ($entrys =~ m/Sponsor/) {
$sponsor = "(Werbung)";
}
$titel =~ s/&/&#38;/g;
$titel =~ s/</&#60;/g;
$titel =~ s/>/&#62;/g;
$titel =~ s/’/'/g;
$titel =~ s/€/Euro/g;
$titel =~ s/£/&#163;/g;
$titel =~ s/©/&#169;/g;
$titel =~ s/®/&#174;/g;
$titel =~ s/«/&#171;/g;
$titel =~ s/»/&#187;/g;
$titel =~ s/"/&quot;/g;
$titel =~ s/–/-/g;
$description =~ s/&/&#38;/g;
$description =~ s/</&#60;/g;
$description =~ s/>/&#62;/g;
$description =~ s/’/'/g;
$description =~ s/€/Euro/g;
$description =~ s/£/&#163;/g;
$description =~ s/©/&#169;/g;
$description =~ s/®/&#174;/g;
$description =~ s/«/&#171;/g;
$description =~ s/»/&#187;/g;
$description =~ s/"/&quot;/g;
$description =~ s/–/-/g;
$description =~ s/\015\012|\015|\012/ /sg;
$description =~ s/ / /g;
$description =~ s/`+/ /g;
print WRITEIT <<EOT;
<item>
<title>$titel</title>
<description>$description $sponsor - Eintrag vom $datum</description>
<link>http://www.domain.de/Detailed/$id.shtml</link>
<guid>http://www.domain.de/Detailed/$id.shtml</guid>
</item>
EOT
}
}
print WRITEIT <<EOT;
</channel>
</rss>
EOT

close(WRITEIT);

print qq|Wrote file to /srv/www/htdocs/web8/html/rss/rss.xml|;

sub get_rssdate {
# --------------------------------------------------------
# Returns the current date.
#
my ($time1) = $_[0];
($time1) or ($time1 = time());
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time1-3600);
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
my @days = qw!Sun Mon Tue Wed Thu Fri Sat!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;
return "$days[$dweek], $day $months[$mon] $year";
}
sub get_time {
# --------------------------------------------------------
# Returns the time in the format "hh-mm-ss".
#
my $time = shift;
$time ||= time();
my ($sec, $min, $hour, @junk) = localtime ($time-3600);
($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");

return "$hour:$min:$sec";
}

Upload to your admin folder, CHMOD to 755, and then run from your browser.

Hopefully that'll work =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Help with RSS In reply to
Thank you very much Andy. Works perfectly!
Quote Reply
Re: [Karl] Help with RSS In reply to
No problem =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!