(* Web page for a given date *)
maintainDate := (
Print["Running maintainDate ..."];
filesample = ToFileName[{dirwork, "templates"}, "date.htm"];
checkfile[filesample];
text0 = Import[filesample, "Text"];
dateset = First /@ csubsets;
Do[
{date, set} = csubset;
place = placeprint[date];
datefull = DateString[date, {"MonthName", " ", "DayShort", ", ", "Year", " (", "DayName", ")"}];
(* datefull = ToString[date[[3]]] <> " " <> rusmonths[[date[[2]]]] <> " " <> ToString[date[[1]]] <> " \:0433\:043e\:0434\:0430"; *)
sd = (" dateS[#, "-"] <> ".htm\">" <> dateS[#, "-"] <> "")&/@dateset;
msd = Length[dateset];
n0 = Position[dateset, date][[1, 1]];
dn = 6;
sd[[n0]] = "" <> dateS[date, "-"] <> "";
If[n0 - dn > 1,
nmin = n0 - dn;
sd[[nmin]] = "...",
nmin = 1;
];
If[n0 + dn < msd,
nmax = n0 + dn;
sd[[nmax]] = "...",
nmax = msd;
];
sd = Take[sd, {nmin, nmax}];
nearestdates = StringJoin[Riffle[sd, " "]];
text = StringReplace[text0, {
"NEARESTDATES" -> nearestdates,
"APIKEY" -> apikey,
"NAMERULAT" -> datefull,
"TOPNAME" -> dateS[date, "-"],
"SPECLOWERUND" -> dateS[date, "-"]
}];
spanRead[text];
spanNew["topline"] = toplinefix[spanOld["topline"]];
spanNew["place"] = If[Head[place] === String && place =!= "", StringReplace[spanOld["place"], "PLACE" -> place], ""];
epilog = StringReplace[epilog0, {"program/sub/maintain-SCRIPTNAME" -> "../program/sub/maintain-date",
"asergeev/" -> "../asergeev/",
"\"program.htm" -> "\"../program.htm",
"\"index" -> "\"../index"}];
(* Weather *)
weather = "";
maintainWeatherDate[date];
If[wtemp =!= "",
weather = "
Weather: " <>
capitalize[wcond] <> wtemp <> wwind <> wprec <>
"
";
];
spanNew["weather"] = weather;
(* *)
spanNew["epilog"] = epilog;
picture0 = spanOld["pictures"];
datasql = Table[
Select[alldatasql, Take[#, 3] === yrp &][[1]], {yrp, set}];
pictures = Table[
{year, roll, pic, capt, xsize, ysize, date, pop} = dat;
alabel = "r" <> roll <> "p" <> pic;
names = mushroomsonpicture[{year, roll, pic}];
repls = Table[
namehtm = StringReplace[ToLowerCase[name], " " -> "_"] <> ".htm";
(name -> " namehtm <> "\">" <> name <> ""), {name, names}];
capt0 = capt;
capt = StringReplace[capt, repls];
(* picture = StringReplace[picture0, {"YEAR" -> year, "ROLL" -> roll, "PIC" -> pic}]; *)
link = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/" <> pic <> ".htm";
linkjpg = "../asergeev/pictures/archives/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> ".jpg";
filejpg = ToFileName[{dir00, "pictures", "archives", year, roll, "jpeg"}, pic <> "b.jpg"];
If[FileType[filejpg] === File, linkjpg = "../asergeev/pictures/archives/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "b.jpg"];
slink = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/" <> pic <> ".htm";
capt1 = " link <> "\" TARGET=\"_blank\" TITLE=\"Photo " <> roll <> "-" <> pic <>
"\">
" <> capt;
(* Location. May be later: shooting data and extra large size *)
filehtm = ToFileName[{dir00, "pictures", "archives", "compress", year, roll}, pic <> ".htm"];
capt2 = "";
If[FileType[filehtm] === File, texthtm = Import[filehtm, "Text"];
match = "";
s = StringCases[texthtm, match];
If[s =!= {}, s = s[[1]];
s = StringReplace[s, {"../../../../../" -> "../asergeev/",
"sh('" ~~ Shortest[x___] ~~ "');" -> "",
" | " -> "",
"staticmap?maptype" -> "staticmap?" <> "key=" <> apikey <> "&" <> "maptype", (* not necessary *)
" " " -> "",
"margin-bottom:2px;" -> "margin-bottom:0px;"}];
capt2 = capt2 <> s;
geolocat = StringReplace[s, Longest[x__] ~~ "&locat=" -> ""];
geolocat = StringReplace[geolocat, "&delay=" ~~ Longest[x__] -> ""];
geolocat = ToExpression["{" <> geolocat <> "}"];
];
];
If[capt2 =!= "",
capt1 = capt1 <> " " <> capt2];
xscale = xsizem1/xsize;
yscale = ysizem1/ysize;
scale = Min[xscale, yscale];
xm = Round[scale xsize];
ym = Round[scale ysize];
wthmaxt = 800;
hthmaxt = 600;
{pw, ph} = {xsize, ysize};
{sc1, sc2} = {wthmaxt, hthmaxt}/{xsize, ysize};
sc = Min[sc1, sc2];
{pwr, phr} = Round[sc {xsize, ysize}];
imgtrail = "ONMOUSEOVER=\"showtrail('../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "m.jpg'," <> ToString[xm] <> "," <> ToString[ym] <> ");" <>
"\" ONMOUSEOUT=\"hidetrail();\"";
link800 = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "x.jpg";
link1200 = "../asergeev/pictures/archives/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> ".jpg";
link600 = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "l.jpg";
link400 = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "m.jpg";
link240 = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "t.jpg";
img0 = "  link800 <> "\" BORDER=\"0\" ALT=\"" <> addsymb[capt0] <> "\">";
(* "\" BORDER=\"0\" HEIGHT=\"" <> ToString[phr] <> "\" WIDTH=\"" <> ToString[pwr] <> "\">"; *)
pictureset = " " <>
" link400 <> "\" media=\"(max-width: 400px)\">
link600 <> "\" media=\"(max-width: 600px)\">
link800 <> "\">
link800 <> "\" BORDER=\"0\" ALT=\"" <> addsymb[capt0] <> "\">
";
jpg = " alabel <> "\" HREF=\"" <> linkjpg <> "\" TARGET=\"_blank\" TITLE=\"Download the picture\">" <> pictureset <> "";
" " <> jpg <>
" " <> capt1 <> " ", {dat, datasql}] // StringJoin;
spanNew["pictures"] = pictures;
spanNew["locationscripts"] = spanNew["locationmap"] = "";
fileloc = ToFileName[{dir0, "date-loc"}, dateS[date, "-"] <> ".kmz"];
If[FileType[fileloc] === File,
spanNew["locationscripts"] = spanOld["locationscripts"];
spanNew["locationmap"] = spanOld["locationmap"]];
text = text // spanReplace;
diren = ToFileName[{dir0, "date-en"}];
checkdir1[diren];
file = ToFileName[diren, dateS[date, "-"] <> ".htm"];
Export[file, text, "Text"], {csubset, csubsets}];
(* Russian version *)
filesample = ToFileName[{dirwork, "templates"}, "date-ru.htm"];
checkfile[filesample];
text0 = Import[filesample, "Text"];
Do[
{date, set} = csubset;
place = placeprint[date];
(* datefull = DateString[date, {"MonthName", " ", "DayShort", ", ", "Year", " (", "DayName", ")"}]; *)
datefull = ToString[date[[3]]] <> " " <> rusmonths[[date[[2]]]] <> " " <> ToString[date[[1]]] <> " \:0433\:043e\:0434\:0430";
sd = (" dateS[#, "-"] <> ".htm\">" <> dateS[#, "-"] <> "")&/@dateset;
msd = Length[dateset];
n0 = Position[dateset, date][[1, 1]];
dn = 6;
sd[[n0]] = " " <> dateS[date, "-"] <> "";
If[n0 - dn > 1,
nmin = n0 - dn;
sd[[nmin]] = "...",
nmin = 1;
];
If[n0 + dn < msd,
nmax = n0 + dn;
sd[[nmax]] = "...",
nmax = msd;
];
sd = Take[sd, {nmin, nmax}];
nearestdates = StringJoin[Riffle[sd, " "]];
text = StringReplace[text0, {
"NEARESTDATES" -> nearestdates,
"APIKEY" -> apikey,
"NAMERULAT" -> datefull,
"TOPNAME" -> dateS[date, "-"],
"SPECLOWERUND" -> dateS[date, "-"]
}];
spanRead[text];
spanNew["topline"] = toplinefix[spanOld["topline"]];
spanNew["place"] = If[Head[place] === String && place =!= "", StringReplace[spanOld["place"], "PLACE" -> place], ""];
(* Weather *)
weather = "";
maintainWeatherDate[date];
If[wtemp =!= "",
wcond = StringReplace[wcond, wTranslations];
weather = " Weather: " <>
capitalize[wcond] <> wtemp <> wwind <> wprec <>
" ";
weather = StringReplace[weather, wTranslations];
];
spanNew["weather"] = weather;
(* *)
epilog = StringReplace[epilogru0, {"program/sub/maintain-SCRIPTNAME" -> "../program/sub/maintain-date",
"asergeev/" -> "../asergeev/",
"\"program-ru.htm" -> "\"../program-ru.htm",
"\"index" -> "\"../index"}];
spanNew["epilog"] = epilog;
picture0 = spanOld["pictures"];
datasql = Table[
Select[alldatasql, Take[#, 3] === yrp &][[1]], {yrp, set}];
pictures = Table[
{year, roll, pic, capt, xsize, ysize, date, pop} = dat;
alabel = "r" <> roll <> "p" <> pic;
names = mushroomsonpicture[{year, roll, pic}];
repls = Table[
(* Add ru-translation *)
rnames = translatename[name, "ru"];
nameru = "";
(*
If[rnames =!= {},
nameru = rnames[[1]];
nameru = " - " <> nameru <> "";
];
*)
namehtm = StringReplace[ToLowerCase[name], " " -> "_"] <> ".htm";
(name -> " namehtm <> "\">" <> name <> "" <> nameru), {name, names}];
capt0 = capt;
capt = StringReplace[capt, repls];
(* picture = StringReplace[picture0, {"YEAR" -> year, "ROLL" -> roll, "PIC" -> pic}]; *)
link = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/" <> pic <> ".htm";
linkjpg = "../asergeev/pictures/archives/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> ".jpg";
filejpg = ToFileName[{dir00, "pictures", "archives", year, roll, "jpeg"}, pic <> "b.jpg"];
If[FileType[filejpg] === File, linkjpg = "../asergeev/pictures/archives/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "b.jpg"];
slink = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/" <> pic <> ".htm";
capt1 = " link <> "\" TARGET=\"_blank\" TITLE=\"Photo " <> roll <> "-" <> pic <>
"\"> " <> capt;
(* Location. May be later: shooting data and extra large size *)
filehtm = ToFileName[{dir00, "pictures", "archives", "compress", year, roll}, pic <> ".htm"];
capt2 = "";
If[FileType[filehtm] === File, texthtm = Import[filehtm, "Text"];
match = " | ";
s = StringCases[texthtm, match];
If[s =!= {}, s = s[[1]];
s = StringReplace[s, {"../../../../../" -> "../asergeev/",
"sh('" ~~ Shortest[x___] ~~ "');" -> "",
" | " -> "",
"staticmap?maptype" -> "staticmap?" <> "key=" <> apikey <> "&" <> "maptype",
" " " -> "",
"margin-bottom:2px;" -> "margin-bottom:0px;"}];
capt2 = capt2 <> s;
geolocat = StringReplace[s, Longest[x__] ~~ "&locat=" -> ""];
geolocat = StringReplace[geolocat, "&delay=" ~~ Longest[x__] -> ""];
geolocat = ToExpression["{" <> geolocat <> "}"];
];
];
If[capt2 =!= "",
capt1 = capt1 <> " " <> capt2];
xscale = xsizem1/xsize;
yscale = ysizem1/ysize;
scale = Min[xscale, yscale];
xm = Round[scale xsize];
ym = Round[scale ysize];
wthmaxt = 800;
hthmaxt = 600;
{pw, ph} = {xsize, ysize};
{sc1, sc2} = {wthmaxt, hthmaxt}/{xsize, ysize};
sc = Min[sc1, sc2];
{pwr, phr} = Round[sc {xsize, ysize}];
imgtrail = "ONMOUSEOVER=\"showtrail('../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "m.jpg'," <> ToString[xm] <> "," <> ToString[ym] <> ");" <>
"\" ONMOUSEOUT=\"hidetrail();\"";
link800 = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "x.jpg";
link1200 = "../asergeev/pictures/archives/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> ".jpg";
link600 = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "l.jpg";
link400 = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "m.jpg";
link240 = "../asergeev/pictures/archives/compress/" <> year <> "/" <> roll <> "/jpeg/" <> pic <> "t.jpg";
img0 = "  link800 <> "\" BORDER=\"0\" ALT=\"" <> addsymb[capt0] <> "\">";
(* "\" BORDER=\"0\" HEIGHT=\"" <> ToString[phr] <> "\" WIDTH=\"" <> ToString[pwr] <> "\">"; *)
pictureset = " " <>
" link400 <> "\" media=\"(max-width: 400px)\">
link600 <> "\" media=\"(max-width: 600px)\">
link800 <> "\">
link800 <> "\" BORDER=\"0\" ALT=\"" <> addsymb[capt0] <> "\">
";
jpg = " alabel <> "\" HREF=\"" <> linkjpg <> "\" TARGET=\"_blank\" TITLE=\"Download the picture\">" <> pictureset <> "";
" " <> jpg <>
" " <> capt1 <> " ", {dat, datasql}] // StringJoin;
spanNew["pictures"] = pictures;
spanNew["locationscripts"] = spanNew["locationmap"] = "";
fileloc = ToFileName[{dir0, "date-loc"}, dateS[date, "-"] <> ".kmz"];
If[FileType[fileloc] === File,
spanNew["locationscripts"] = spanOld["locationscripts"];
spanNew["locationmap"] = spanOld["locationmap"]];
text = text // spanReplace;
dirru = ToFileName[{dir0, "date-ru"}];
checkdir1[dirru];
file = ToFileName[dirru, dateS[date, "-"] <> ".htm"];
Export[file, text, "Text"], {csubset, csubsets}];
);
|