program vc2;

{$MODE OBJFPC}{$H+}
{$linklib c}

{
    Voice Clock.
    For GNU/Linux 64 bit version.
    Version: 1.
    Written on FreePascal (https://freepascal.org/).
    Copyright (C) 2025  Artyomov Alexander
    Used https://chat.deepseek.com/
    http://self-made-free.ru/
    aralni@mail.ru

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
}

uses sysutils,unix,time,Math;

Var HH,MM,SS,MS, YY,NN,DD: Word;
t:string='';
c:string='';
fp:TextFile;
exedir:string='';
IT:Double;

begin

exedir := ExtractFilePath(ExpandFileName(ParamStr(0)));
 if popen (fp, exedir + 'termometerwttr', 'r') = 0 then begin
 readln(fp, c);
 pclose(fp);
 end else c := 'na';
if c = 'na' then begin
 if popen (fp, exedir + 'termometeropenweathermap', 'r') = 0 then begin
 readln(fp, c);
 pclose(fp);
 end;
end;
WriteLn(c);
if c <> 'na' then begin
IT:=StrToFloatDef(c,0.0);
if it < 0 then t := ' ~/.gorg64/voicedigits/t/minus.wav';
t := t + ' ~/.gorg64/voicedigits/t/t'+IntToStr(Abs(Round(IT)))+'.wav';
end;

DecodeTime(sysutils.Time,HH,MM,SS,MS);
DecodeDate(sysutils.Date,YY,NN,DD);
Writeln(format('The time is %d:%d:%d',[hh,mm,ss]));
Writeln(format('The date is %d:%d:%d',[yy,nn,dd]));

fpSystem('mplayer ' + '~/.gorg64/voicedigits/h/h'+IntToStr(HH)+'.wav' +
' ~/.gorg64/voicedigits/m/m'+IntToStr(MM)+'.wav'  + ' ~/.gorg64/voicedigits/d/d'+IntToStr(DD)+'.wav' +
' ~/.gorg64/voicedigits/n/n'+IntToStr(nn)+'.wav' + ' ~/.gorg64/voicedigits/w/w'+IntToStr(WeekdayRu(YY,NN,DD))+'.wav' +
' ~/.gorg64/voicedigits/y/y'+IntToStr(yy)+'.wav' + t);

end.