1 | #!/usr/bin/perl -w
|
---|
2 | #
|
---|
3 | # Creates news html pages
|
---|
4 | #
|
---|
5 | # $Id$
|
---|
6 | #
|
---|
7 | # Syntax : mknewshtml.pl dir
|
---|
8 | #
|
---|
9 |
|
---|
10 | use strict;
|
---|
11 | use Date::Manip;
|
---|
12 | use File::Basename;
|
---|
13 | use DBI;
|
---|
14 | use English;
|
---|
15 |
|
---|
16 |
|
---|
17 | # For date handling
|
---|
18 | $ENV{LANG}="C";
|
---|
19 |
|
---|
20 | my $TOOLHOME;
|
---|
21 | my $tmp = dirname($PROGRAM_NAME);
|
---|
22 | if ($tmp =~ /^\//) {
|
---|
23 | $TOOLHOME = $tmp;
|
---|
24 | }
|
---|
25 | else {
|
---|
26 | $TOOLHOME = "$ENV{PWD}/$tmp";
|
---|
27 | }
|
---|
28 |
|
---|
29 | my $lastnews="$ARGV[0]/latest-news.html";
|
---|
30 | my $news="$ARGV[0]/news.shtml";
|
---|
31 | my $db="$TOOLHOME/../website/announces3.sql";
|
---|
32 |
|
---|
33 | print "Using Database $db\n";
|
---|
34 |
|
---|
35 | my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","")
|
---|
36 | || die "Unable to connect to $db";
|
---|
37 |
|
---|
38 | open(NEWS,"> $news") || die "Unable to open $news (write)";
|
---|
39 | print 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 |
|
---|
55 | EOF
|
---|
56 |
|
---|
57 | my $today = &UnixDate("today","%Y-%m-%d");
|
---|
58 | my $firstjan = &UnixDate("1st January","%Y-%m-%d");
|
---|
59 | #print "today: $today - First: $firstjan\n";
|
---|
60 |
|
---|
61 | my $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 |
|
---|
67 | print NEWS << 'EOF';
|
---|
68 |
|
---|
69 | <div class="h2-2">
|
---|
70 | <h2>Last year's News</h2>
|
---|
71 | </div>
|
---|
72 |
|
---|
73 | EOF
|
---|
74 |
|
---|
75 | my $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 |
|
---|
85 | print NEWS << 'EOF';
|
---|
86 |
|
---|
87 | <div class="h2-3">
|
---|
88 | <h2>Older News</h2>
|
---|
89 | </div>
|
---|
90 |
|
---|
91 | EOF
|
---|
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 |
|
---|
100 | print 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>
|
---|
113 | EOF
|
---|
114 |
|
---|
115 | close(NEWS);
|
---|
116 |
|
---|
117 | my $cpt = 3;
|
---|
118 | open(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;
|
---|