]> www.wagner.pp.ru Git - oss/imgwww.git/blob - archivedir
Moved from imagemagick to netpbm for scaling
[oss/imgwww.git] / archivedir
1 #!/usr/bin/tclsh
2
3 array set monName {
4 01 "\u042f\u043d\u0432\u0430\u0440\u044f"
5 02 "\u0424\u0435\u0432\u0440\u0430\u043b\u044f"
6 03 "\u041c\u0430\u0440\u0442\u0430"
7 04 "\u0410\u043f\u0440\u0435\u043b\u044f"
8 05 "\u041c\u0430\u044f"
9 06 "\u0418\u044e\u043d\u044f"
10 07 "\u0418\u044e\u043b\u044f"
11 08 "\u0410\u0432\u0433\u0443\u0441\u0442\u0430"
12 09 "\u0421\u0435\u043d\u0442\u044f\u0431\u0440\u044f"
13 10 "\u041e\u043a\u0442\u044f\u0431\u0440\u044f"
14 11 "\u041d\u043e\u044f\u0431\u0440\u044f"
15 12 "\u0414\u0435\u043a\u0430\u0431\u0440\u044f"
16 }
17
18 proc try_save { data filename } {
19
20         if {[catch {
21                         set f [open $filename "r"]
22                         set d [read $f]
23                         close $f
24         }]} {
25                 set d ""
26         }
27         if {![string equal $data $d]} {
28                 puts stderr "Writing $filename"
29                 set f [open $filename "w"]
30                 puts -nonewline $f $data
31                 close $f
32         }
33 }
34
35 proc out_item { month day place dir} {
36         global monName
37         return "<li><a href=\"$month.$day-$place\">$day $monName($month)</a> $place</li>\n"
38 }
39 proc nextyearlink {year} {
40         if {![string length $year]} {
41                 return "&nbsp;"
42         } else {
43                 return "<a href=\"$year\">$year</a>"
44         }
45 }
46 set years "<HTML><HEAD><TITLE>\u0410\u0440\u0445\u0438\u0432 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0439</TITLE></HEAD><BODY>
47 <H1>\u0410\u0440\u0445\u0438\u0432
48 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0439</H1>\n<ul>\n"
49 foreach dirname [lsort -decreasing [glob */*]] {
50         if {![regexp {^(\d{4})/(\d{2})\.(\d{2}(-\d{2})?)-(.*)$} $dirname \
51                         match year month day xxx place]} {
52                         continue
53         }       
54         lappend a($year) [list $month $day $place [llength [glob $dirname/*.html]]]
55 }       
56
57 set html_finish "</ul>\n<hr><font size=\"-2\">Copyright &copy; Vitus Wagner</font>\n</body></html>\n"
58 set yearlist [lsort -decreasing [array names a]]
59 for {set i 0} {$i<[llength $yearlist]} {incr i}  {
60         set y [lindex $yearlist $i]
61         set title "\u0424\u043e\u0442\u043e\u0430\u0440\u0445\u0438\u0432 $y \u0433\u043e\u0434"
62         set yearindex "<HTML><HEAD><TITLE>$title</TITLE><HEAD>"
63         append yearindex "<table border=0 width=\"100%\"><tr><td align=left>"
64         append yearindex [nextyearlink [lindex $yearlist [expr $i+1]]]
65         append yearindex "</td><td align=\"center\"><a href=\"..\">back</a></td><td align=\"right\">"
66         append yearindex [nextyearlink  [lindex $yearlist [expr $i-1]]]
67         append yearindex "</td><tr></table\n><h1>$title</h1>\n<ul>"
68         set dircount [llength $a($y)]
69         set count 0
70         foreach item $a($y) {
71                 incr count [expr {[lindex $item 3]-1}]
72                 append yearindex [eval out_item $item]
73         }
74         append yearindex $html_finish
75         try_save $yearindex "$y/index.html"
76         append years "<li><a href=\"$y\">$y</a> ($dircount \u0434\u043d\u0435\u0439, $count \u0444\u043e\u0442\u043e)\n"
77 }       
78
79
80 append years $html_finish
81 try_save $years "index.html"