
{
    Termometer ya.ru
    For GNU/Linux.
    Version: 2.
    Written on FreePascal (https://freepascal.org/).
    Copyright (C) 2026  Artyomov Alexander
    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/>.
}

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

uses
sysutils, unix;

var
fp: Text;
s,val:string;
p,f,ff:LongInt;
c:char;
minus_sign:boolean=false;

begin

if fpSystem('wget -O /tmp/yterm.txt "https://yandex.ru/pogoda/ru/moscow?lat=55.755863&lon=37.6177" > /dev/null 2>/dev/null') = 0 then
WriteLn(stderr, '* Downloaded')
else begin
WriteLn(stderr, '>>> Downloading error');
WriteLn('na');
Halt;
end;

Assign(fp, '/tmp/yterm.txt');

ReSet(fp);

while not eof(fp) do begin

readln(fp, s);

p := Pos('<span class="AppFactTemperature_sign', s);
if p <> 0 then begin
for f := p to Length(s) do begin
if s[f] = '>' then begin
 c := s[f+1];
 case c of
 '+':minus_sign:=false;
 '-':minus_sign:=true;
 else
WriteLn(stderr, 'Error sign');
WriteLn('na');
Halt;
 end;
WriteLn(stderr, '* Sign extracted');
 break;
end;
end; {next f}
end;

p := Pos('<span class="AppFactTemperature_value', s);
if p <> 0 then begin
val:='';
for f := p to Length(s) do begin
if s[f] = '>' then begin

for ff := f+1 to Length(s) do begin
if s[ff] = '<' then begin
if minus_sign then val := '-'+val;
WriteLn(stderr, '* Value extracted');
WriteLn(val);
Halt;
end;
val:=val+s[ff];
end; {next ff}

end;
end; {next f}
end;

end;

WriteLn('na');

close(fp);

end.