#!/usr/bin/tclsh
array set monName {
01 "\u042f\u043d\u0432\u0430\u0440\u044f"
02 "\u0424\u0435\u0432\u0440\u0430\u043b\u044f"
03 "\u041c\u0430\u0440\u0442\u0430"
04 "\u0410\u043f\u0440\u0435\u043b\u044f"
05 "\u041c\u0430\u044f"
06 "\u0418\u044e\u043d\u044f"
07 "\u0418\u044e\u043b\u044f"
08 "\u0410\u0432\u0433\u0443\u0441\u0442\u0430"
09 "\u0421\u0435\u043d\u0442\u044f\u0431\u0440\u044f"
10 "\u041e\u043a\u0442\u044f\u0431\u0440\u044f"
11 "\u041d\u043e\u044f\u0431\u0440\u044f"
12 "\u0414\u0435\u043a\u0430\u0431\u0440\u044f"
}
proc try_save { data filename } {
if {[catch {
set f [open $filename "r"]
set d [read $f]
close $f
}]} {
set d ""
}
if {![string equal $data $d]} {
puts stderr "Writing $filename"
set f [open $filename "w"]
puts -nonewline $f $data
close $f
}
}
proc out_item { month day place dir} {
global monName
return "
$day $monName($month) $place\n"
}
proc nextyearlink {year} {
if {![string length $year]} {
return " "
} else {
return "$year"
}
}
set years "\u0410\u0440\u0445\u0438\u0432 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0439
\u0410\u0440\u0445\u0438\u0432
\u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0439
\n\n"
foreach dirname [lsort -decreasing [glob */*]] {
if {![regexp {^(\d{4})/(\d{2})\.(\d{2}(-\d{2})?)-(.*)$} $dirname \
match year month day xxx place]} {
continue
}
lappend a($year) [list $month $day $place [llength [glob $dirname/*.html]]]
}
set html_finish "
\n
Copyright © Vitus Wagner\n\n"
set yearlist [lsort -decreasing [array names a]]
for {set i 0} {$i<[llength $yearlist]} {incr i} {
set y [lindex $yearlist $i]
set title "\u0424\u043e\u0442\u043e\u0430\u0440\u0445\u0438\u0432 $y \u0433\u043e\u0434"
set yearindex "$title"
append yearindex ""
append yearindex [nextyearlink [lindex $yearlist [expr $i+1]]]
append yearindex " | back | "
append yearindex [nextyearlink [lindex $yearlist [expr $i-1]]]
append yearindex " |
|
$title
\n"
set dircount [llength $a($y)]
set count 0
foreach item $a($y) {
incr count [expr {[lindex $item 3]-1}]
append yearindex [eval out_item $item]
}
append yearindex $html_finish
try_save $yearindex "$y/index.html"
append years "- $y ($dircount \u0434\u043d\u0435\u0439, $count \u0444\u043e\u0442\u043e)\n"
}
append years $html_finish
try_save $years "index.html"