source: devel/pb/bin/mknewshtml.pl @ 5

Last change on this file since 5 was 5, checked in by bruno, 12 years ago

Lots of modifs to find the right way. Probably still not good

  • Property svn:executable set to *
File size: 2.9 KB
Line 
1#!/usr/bin/perl -w
2#
3# Creates news html pages
4#
5# $Id$
6#
7# Syntax : mknewshtml.pl dir
8#
9
10use strict;
11use Date::Manip;
12use File::Basename;
13use DBI;
14use English;
15
16
17# For date handling
18$ENV{LANG}="C";
19
20my $PBROOT;
21my $tmp = dirname($PROGRAM_NAME);
22if ($tmp =~ /^\//) {
23    $PBROOT = $tmp;
24    }
25else {
26    $PBROOT = "$ENV{PWD}/$tmp";
27    }
28
29my $lastnews="$ARGV[0]/latest-news.html";
30my $news="$ARGV[0]/news.shtml";
31my $db="$PBROOT/../website/announces3.sql";
32
33print "Using Database $db\n";
34
35my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","") 
36            || die "Unable to connect to $db";
37
38open(NEWS,"> $news") || die "Unable to open $news (write)";
39print NEWS << 'EOF';
40<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x html1/DTD/xhtml1-strict.dtd">
41
42<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="en" lang="en">
43  <head>
44<!--#include virtual="/head.shtml" -->
45  </head>
46  <body>
47                  <!--#set var="curpage" value="news.shtml" -->
48<!--#include virtual="/top.shtml" -->
49
50                <h1>Mondo Rescue News</h1>
51  <div class="h2-1">
52    <h2>This year's News</h2>
53  </div>
54
55EOF
56
57my $today = &UnixDate("today","%Y-%m-%d");
58my $firstjan = &UnixDate("1st January","%Y-%m-%d");
59#print "today: $today - First: $firstjan\n";
60
61my $all = $dbh->selectall_arrayref("SELECT id,date,announce FROM announces ORDER BY date DESC");
62  foreach my $row (@$all) {
63    my ($id, $date, $announce) = @$row;
64    print NEWS "<p><B>$date</B> $announce\n" if ((Date_Cmp($date,$today) <= 0) && (Date_Cmp($firstjan,$date) <= 0));
65  }
66
67print NEWS << 'EOF';
68
69  <div class="h2-2">
70    <h2>Last year's News</h2>
71  </div>
72
73EOF
74
75my $oldfirst = &UnixDate(DateCalc("1st January","1 year ago"),"%Y-%m-%d");
76#print "oldfirst: $oldfirst - First: $firstjan\n";
77
78$all = $dbh->selectall_arrayref("SELECT id,date,announce FROM announces ORDER BY date DESC");
79  foreach my $row (@$all) {
80    my ($id, $date, $announce) = @$row;
81    print NEWS "<p><B>$date</B> $announce\n" if ((Date_Cmp($date,$firstjan) <= 0) && (Date_Cmp($oldfirst,$date) <= 0));
82  }
83
84
85print NEWS << 'EOF';
86
87  <div class="h2-3">
88    <h2>Older News</h2>
89  </div>
90
91EOF
92
93$all = $dbh->selectall_arrayref("SELECT id,date,announce FROM announces ORDER BY date DESC");
94  foreach my $row (@$all) {
95    my ($id, $date, $announce) = @$row;
96    print NEWS "<p><B>$date</B> $announce\n" if ((Date_Cmp($oldfirst,$date) >= 0));
97  }
98
99
100print NEWS << 'EOF';
101
102  <div class="h2-4">
103    <h2>Oldest News</h2>
104  </div>
105
106   <p>look at these pages for old News concerning the project</p>
107  <p><a href="gossip.html">Hugo's diary preserved (2001-2003)</a>
108  </p>
109
110<!--#include virtual="/bottom.shtml" -->
111  </body>
112</html>
113EOF
114
115close(NEWS);
116
117my $cpt = 4;
118open(NEWS,"> $lastnews") || die "Unable to open $lastnews (write)";
119$all = $dbh->selectall_arrayref("SELECT id,date,announce FROM announces ORDER BY date DESC");
120  foreach my $row (@$all) {
121    my ($id, $date, $announce) = @$row;
122    print NEWS "<p><B>$date</B> $announce\n" if ($cpt > 0);
123    $cpt--
124  }
125
126$dbh->disconnect;
Note: See TracBrowser for help on using the repository browser.