]> git.donarmstrong.com Git - catcam.git/commitdiff
add index.cgi for catcam
authorDon Armstrong <don@donarmstrong.com>
Sun, 11 Dec 2016 20:15:54 +0000 (12:15 -0800)
committerDon Armstrong <don@donarmstrong.com>
Sun, 11 Dec 2016 20:15:54 +0000 (12:15 -0800)
index.cgi [new file with mode: 0755]

diff --git a/index.cgi b/index.cgi
new file mode 100755 (executable)
index 0000000..7035f47
--- /dev/null
+++ b/index.cgi
@@ -0,0 +1,68 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use CGI::Simple;
+use File::Find;
+use File::stat;
+
+my $q = CGI::Simple->new({num=>100});
+
+my $cat_dir = '/home/don/debian/.cat/';
+
+
+my %pics;
+find(sub {
+         if (/\.html$/) {
+             $pics{$_} = stat($_);
+         }
+      },
+     $cat_dir);
+
+print $q->header(-status => 200);
+
+print <<EOF;
+<!DOCTYPE html>
+<html>
+<head>
+<title>Cat Pictures!</title>
+</head>
+<body>
+<header class="header"><span class="title">Cat Pictures!</span></header>
+
+<section class="catpictures">
+EOF
+
+my $num = 0;
+my $previous_date = '';
+for my $pic (sort {$pics{$b}->ctime <=> $pics{$a}->ctime} keys %pics) {
+    my $this_date = POSIX::strftime('%Y-%m-%d',time($pics{$pic}->ctime));
+    if ($previous_date ne $this_date){
+        print "<p>$this_date</p>\n";
+        $this_date = $previous_date;
+    }
+    my $basename = $pic;
+    $basename =~ s/\.html//;
+    print <<EOF;
+<a href="$pic"><img src="${basename}.jpg" width=100 height=100 alt="$basename"></a>
+EOF
+    $num++;
+    last if $num > 30;
+}
+
+print <<EOF;
+</section>
+<footer>
+<span class="footer">A silly CGI script</span>
+</footer>
+</html>
+EOF
+
+sub error {
+    my ($q,$error,$text) = @_;
+    $text //= '';
+    print $q->header(-status => $error);
+    print "<h2>$error: $text</h2>";
+    exit 0;
+}